I'm having an issue with toggling my navbar visibility on click of an image. It works the first time but not after that. Can anyone provide some assistance?
<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) The toolbar should show on page load - it is showing as expected https://i.stack.imgur.com/RqjGS.png
2) Clicking the icon at the top left corner should hide the toolbar - working first time https://i.stack.imgur.com/RsamL.png
3) Clicking the icon again should display the toolbar - currently NOT working