我正在创建一个angular 7应用程序,并使用有角度的材质side-nav bar。我想在单击side-nav出现并关闭side-nav时将汉堡菜单更改为十字形图标,然后将十字图标更改为汉堡菜单图标。
//html code
<mat-sidenav-container class="sidenav-container">
<mat-sidenav #drawer class="sidenav" fixedInViewport="true"
[attr.role]="'dialog'"
[mode]="'over'"
[opened]="!(isHandset$ | async)">
<mat-toolbar>Menu</mat-toolbar>
<mat-nav-list>
<a mat-list-item href="#">Link 1</a>
<a mat-list-item href="#">Link 2</a>
<a mat-list-item href="#">Link 3</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="true">
<mat-icon aria-label="Side nav toggle icon">menu</mat-icon>
</button>
<span>web-doctor</span>
</mat-toolbar>
<div style="height: 500px">abc</div>
<ng-content>
</ng-content>
</mat-sidenav-content>
</mat-sidenav-container>
css文件下方
//css
.sidenav-container {
height: 100%;
}
.sidenav {
width: 200px;
margin-top: 72px;
}
.sidenav .mat-toolbar {
background: inherit;
}
#drawer {
position: fixed;
}
.mat-toolbar.mat-primary {
position: sticky;
top: 0;
z-index: 1;
}
答案 0 :(得分:1)
您可以使用ngIf
。
<mat-toolbar color="primary">
<button
type="button"
aria-label="Toggle sidenav"
mat-icon-button
(click)="drawer.toggle()"
*ngIf="true">
<mat-icon aria-label="Side nav toggle icon" *ngIf="!drawer.opened; else showCross">
menu
</mat-icon>
<ng-template #showCross>
<mat-icon aria-label="Side nav toggle icon">close</mat-icon>
</ng-template>
</button>
<span>web-doctor</span>
</mat-toolbar>