We have a toolbar component that is the layout container for the entire application.
dashboard.html:
<md-sidenav-layout class="sidenav-layout">
<bv-toolbar (toggleSidenav)="start.toggle()" [screenWidth]="screenWidth"></bv-toolbar>
<md-sidenav #start [opened]="screenWidth > 1000" [mode]="(screenWidth > 1000) ? 'side' : 'start'">
<bv-sidenav-content [user]="user$ | async" [screenWidth]="screenWidth" (navClose)="start.toggle()"></bv-sidenav-content>
</md-sidenav>
<div class="sidenav-content"></div>
</md-sidenav-layout>
, ( sidenav) [screenWidth]="screenWidth".
dashboard.ts:
...
export class DashboardComponent {
screenWidth: number;
...
constructor (private cdr: ChangeDetectorRef, private store: Store<fromRoot.State> ) {
var that = this;
// set screenWidth on page load
that.screenWidth = window.innerWidth;
window.onresize = () => {
// set screenWidth on screen size change
that.screenWidth = window.innerWidth;
that.cdr.detectChanges();
}
}
, screenWidth , script @Input(), .
toolbar.ts:
...
export class ToolbarComponent {
@Output() toggleSidenav = new EventEmitter();
@Input() screenWidth : number;
}
screenWidth, , ( .
toolbar.html:
<md-toolbar color="primary">
<button md-icon-button
(click)="toggleSidenav.emit()"
[ngClass]="{'h-hide': screenWidth > 1000}">
<md-icon>menu</md-icon>
</button>
</md-toolbar>