gpt4 book ai didi

带路由器的 Angular2 Material 设计 mdtabs

转载 作者:太空狗 更新时间:2023-10-29 19:36:22 31 4
gpt4 key购买 nike

我无法为路由工作制作标签 ( from angular material 2 docs ):

组件:

export class AppComponent {
navLinks: [
'/groups',
'/objects'
]
}

html:

<nav md-tab-nav-bar>
<a md-tab-link
*ngFor="let link of navLinks"
[routerLink]="link"
routerLinkActive #rla="routerLinkActive"
[active]="rla.isActive">
{{tabLink.label}}
</a>
</nav>

<router-outlet></router-outlet>

日志中没有错误可能很明显,但仍然...

最佳答案

下面的代码可以正常工作

<nav md-tab-nav-bar aria-label="weather navigation links">
<a md-tab-link
*ngFor="let routeLink of routeLinks; let i = index"
[routerLink]="routeLink.link"
[active]="activeLinkIndex === i"
(click)="activeLinkIndex = i">
{{routeLink.label}}
</a>
</nav>
<router-outlet></router-outlet>

我的组件代码看起来像,

export class App {
routeLinks:any[];
activeLinkIndex = 0;
constructor(private router: Router) {
this.routeLinks = [
{label: 'Welcome', link: 'welcome'},
{label: 'Home', link: 'home'}];

}
}

LIVE DEMO

关于带路由器的 Angular2 Material 设计 mdtabs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42600772/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com