使用 Angular Angular Material 12
如果您想關閉 MatSidenav,那么我找到的幾乎所有解決方案都說:
(click)="sidenav.close()"在 html 組件中。
但是我的注銷功能需要那個(點擊) (click)="onLogoutSideNav()"
onLogoutSideNav() {
this.authService.logout();
}
我需要從組件中的方法內部而不是從 html 中關閉 MatSidenav。我能找到的唯一解決方案是:
sidenav!: MatSidenav
...
onLogoutSideNav() {
this.authService.logout();
this.sidenav.close();
}
但是這樣做會為 this.sidenav 回傳 undefined。
有很多使用@ViewChild 的解決方案,但我沒有將我的導航分成標題和側邊欄組件。我保持簡單,在 app.component 中這樣做。
<mat-list-item *ngIf="isAuth" routerLink="/"><button mat-icon-button><mat-icon>logout</mat-icon><span class="sidenav-span" (click)="onLogoutSideNav()">Logout</span></button></mat-list-item>
我在這里錯過了什么?
uj5u.com熱心網友回復:
您可以在單擊事件上呼叫多個函式。例如 =>
(click)="onLogoutSideNav();test()"
希望這能回答你的問題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/360863.html
標籤:javascript 有角的 角材料 mat-sidenav
上一篇:如何在不將ACTUAL影像存盤在我的前端或資料庫中的情況下向我的應用程式顯示影像?
下一篇:根據json屬性動態改變顏色
