按钮在导航栏中,它位于与侧栏不同的组件中。我的布局看起来是这样的:
<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)">
<app-sidebar></app-sidebar>
</mat-sidenav>
<mat-sidenav-content>
<app-navbar></app-navbar>
</mat-sidenav-content>
</mat-sidenav-container>在肚脐上,我有一个按钮:
<button mat-icon-button (click)="drawer.toggle()">
<mat-icon>menu</mat-icon>
</button>发布于 2018-06-19 04:30:51
可以将侧栏设置为导航条中的子组件为@ViewChild('drawer') drawer: ElementRef;,也可以在侧栏组件中创建切换类,并在导航栏组件中使用@ViewChild(SidebarComponent) child: SidebarComponent;并将其与this.child.'class_in_sidebar'切换。
https://stackoverflow.com/questions/50920220
复制相似问题