I am trying to show hide my navbar on click of an image. On first click it is working, after that it doesn't. Not sure what is wrong. Any help please???
https://stackblitz.com/edit/responsive-menu-angular-material-flex-layout-cm87il
<img id="project-avatar" (click)="toggleNavbar()" width=20, height=20 style="position: relative;" alt="Show Hide Navigation Menu" src="/assets/img/slider_hide.png" />
<div>
<div class="showHideNavbar" [ngStyle]="displayNavbar == '1' ? {'visibility': 'visible'} : {'visibility': 'hidden'}">
<mat-toolbar color="primary" >
component.ts
displayNavbar: string;
ngOnInit() {
this.displayNavbar = '1';
}
toggleNavbar() {
if(this.displayNavbar == '0') {
this.displayNavbar = '1';
alert(this.displayNavbar);
} if(this.displayNavbar == '1') {
// alert("1 - Changing to 0");
this.displayNavbar = '0';
} else {
this.displayNavbar = '1';
}
}
1) Onload of the page the toolbar should show - it is showing as expected

2) On click of the icon(at top left corner), the toolbar should hide - it is working first time

3) On click of the icon again, the toolbar should display again - it is NOT working
https://stackblitz.com/edit/responsive-menu-angular-material-flex-layout-cm87il
[hidden]and a boolean flag. Or alternatively*ngIf.[hidden]and boolean flag instead. Much cleaner ;) stackblitz.com/edit/…