我目前面臨一個無法解決的問題:我正在嘗試構建一個 Angular Material 步進器。每個步驟都應該將用戶帶到我的專案中的不同組件。
我在我的 .ts 檔案中撰寫了一些函式,當在我的 .html 檔案中呼叫時,這些函式將用戶導航到特定組件。不幸的是,這種 click-Event 不適合<mat-step>,而只適用于<p>. 這意味著,我的路由型別有效,但前提是我點擊了確切的文本元素<p>而不是“整個步驟容器” <mat-step>。
我現在正在尋找一種更優雅的方法來解決這個問題 - 提前感謝您的每一條評論!小心 :)
goto_component1() {
this.route.navigate(['/component1']);
}
goto_component2() {
this.route.navigate(['/component2']);
}
<mat-horizontal-stepper>
<mat-step>
<ng-template matStepLabel>
<p (click)="goto_component1()">Component One</p>
</ng-template>
</mat-step>
<mat-step>
<ng-template matStepLabel>
<p (click)="goto_component2()">Component Two</p>
</ng-template>
</mat-step>
</mat-horizontal-stepper>
uj5u.com熱心網友回復:
使用 selectionChange 事件檢測選項卡更改,并使用索引查找單擊了哪個選項卡
<mat-horizontal-stepper(selectionChange)="goto_component1($event)">
</mat-horizontal-stepper>
您將從 $event 中獲得 selectedIndex ,您可以使用它來查找單擊的選項卡
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/352518.html
下一篇:發出空字串事件會導致一個物件嗎?
