mat-sidenav
已打开。我该如何关闭?
这是我的HTML:
<mat-sidenav
#drawer
class="sidenav" position="end"
fixedInViewport="true"
[attr.role]="(isHandset$ | async) ? 'dialog' : 'navigation'"
[mode]="(isHandset$ | async) ? 'over' : 'side'"
[opened]="!(isHandset$ | async)">
<mat-toolbar color="warn">Menu</mat-toolbar>
<mat-nav-list>
<a mat-list-item [routerLink] = "['/brands']"> Brands </a>
<a mat-list-item [routerLink] = "['/variants']"> Variants </a>
</mat-nav-list>
</mat-sidenav>
另外,当我点击页面中的任何位置时,我希望它接近(打开时)。目前只有在我点击菜单按钮时它才会关闭。
答案 0 :(得分:0)
试试以下,
<mat-sidenav-container class="sidenav-container">
<mat-sidenav
#drawer
class="sidenav"
fixedInViewport="true"
[attr.role]="(isHandset$ | async) ? 'dialog' : 'navigation'"
[mode]="(isHandset$ | async) ? 'over' : 'side'"
[opened]="!(isHandset$ | async)">
<mat-toolbar color="warn">Menu</mat-toolbar>
<mat-nav-list>
<a mat-list-item [routerLink] = "['/brands']"> Brands </a>
<a mat-list-item [routerLink] = "['/variants']"> Variants </a>
</mat-nav-list>
</mat-sidenav>
<mat-sidenav-content>
<mat-toolbar color="primary">
<button
type="button"
aria-label="Toggle sidenav"
mat-icon-button
(click)="drawer.toggle()"
*ngIf="isHandset$ | async">
<mat-icon aria-label="Side nav toggle icon">menu</mat-icon>
</button>
<span>Application Title</span>
</mat-toolbar>
</mat-sidenav-content>
</mat-sidenav-container>
答案 1 :(得分:0)
您可以尝试它对我的身体很好
<mat-nav-list>
<a mat-list-item [routerLink] = "['/brands']" (click)="drawer.close()"> Brands </a>
<a mat-list-item [routerLink] = "['/variants']" (click)="drawer.close()"> Variants </a>
</mat-nav-list>