[英]how can apply routerLinkActive directive to this.router.navigate(...) method in angular?;
我們可以將 routerLinkActive 指令與 [routerLink] 一起簡單地應用為:
<a [routerLink]="'/profile'" routerLinkActive="active"> My Profile </a>
當然是標簽<a></a>
。 但是如果我們想按以下方式導航以執行操作:.ts 文件:
navigateToMyProfile(): void { this.router.navigate(['/profile']); }
<mat-list-item (click)="navigateToMyProfile()">
我們在哪里可以為上述方法應用 routerLinkActive 指令? 最好的祝福
請改用mat-list-item
作為屬性。
將
mat-nav-list
標簽用於導航列表(即具有錨標簽的列表)。簡單的導航列表可以直接在錨標簽元素上使用
mat-list-item
屬性
<mat-nav-list>
<a mat-list-item routerLink="/profile" routerLinkActive="active">My Profile</a>
</mat-nav-list>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.