To control the visibility of the sidenav button and toolbar content, you can implement a boolean flag with ngIf
. This flag can be toggled using the window:resize
event.
For example, you can display the sidenav differently for screen sizes below 720px compared to those greater than or equal to 720px.
Here's how it can be achieved:
<md-toolbar [color]="toolbarColor">
<button *ngIf="openSidenavFlag" md-button color="primary" (click)="sidenav.toggle()">
<md-icon>menu</md-icon>
</button>
<h1>Angular</h1>
<div *ngIf="!openSidenavFlag" style="margin: 0 auto">
<button md-button>Blog</button>
<button md-button>About</button>
<button md-button>Contact</button>
</div>
</md-toolbar>
<div fxFlex class="app-content">
This is the content
</div>
<md-sidenav-container (window:resize)="onResize($event)" style="height: 91vh;background: #FFFFFF">
<md-sidenav #sidenav mode="side" style="background: orange">
Sidenav!
</md-sidenav>
</md-sidenav-container>
<footer style="background: skyblue">This is footer</footer>
ts:
openSidenavFlag = false;
constructor() {
}
ngOnInit(){
this.onResize();
}
onResize(event) {
let width;
if(event != undefined){
width = event.target.innerWidth;
// console.log(event.target.innerWidth);
}
else{
// console.log(document.body.clientWidth);
width = document.body.clientWidth;
}
if (width >= 720) {
this.openSidenavFlag = false;
}
else {
this.openSidenavFlag = true;
}
}
Plunker demo