I'm trying to set the behavior of MatSideNav through component file using a property of type MatDrawer in Angular version 8
TypeScript Code:
// Declaration
@ViewChild('drawer', { static: false }) public drawer: MatDrawer;
// Toggle the Side Nav bar
showSideNav(): void {
this.drawer.toggle();
}
HTML Code:
<mat-drawer-container>
<mat-drawer #drawer>
<div>Side nav bar content</div>
</mat-drawer>
<div>Main content</div>
</mat-drawer-container>
Console Error:
ERROR TypeError: "this.drawer is undefined"
Kindly assist me how to access the MatDrawer
element using @ViewChild