Angular2 将 active class 分配给 li 标签
Angular2 assign active class to the li tag
我想将活动 class 分配给 angular2 中的 li 标签,但卡住了。
这是我试过的
<li [class.active]=" _router.isRouteActive(_router.generate(['/dashboard']))" >
//the above _router.isRouteActive throws an error
<a routerLink="/dashboard">
<i class="icon-display4 position-left"></i> Dashboard</a>
</li>
在我的 ts 文件中我有
export class SecondaryNavComponent implements OnInit {
//thinking of using to determine active link
constructor(public _router:Router) { } //tried also with private
ngOnInit() {
}
}
错误显示
ERROR TypeError: co._router.generate is not a function
ALse webstorm generates an error that
unkwon method router is active
有什么问题吗?
只需为此使用 RouterLinkActive 指令:
https://angular.io/docs/ts/latest/api/router/index/RouterLinkActive-directive.html
它已经在 @angular/router
包中。
我想将活动 class 分配给 angular2 中的 li 标签,但卡住了。
这是我试过的
<li [class.active]=" _router.isRouteActive(_router.generate(['/dashboard']))" >
//the above _router.isRouteActive throws an error
<a routerLink="/dashboard">
<i class="icon-display4 position-left"></i> Dashboard</a>
</li>
在我的 ts 文件中我有
export class SecondaryNavComponent implements OnInit {
//thinking of using to determine active link
constructor(public _router:Router) { } //tried also with private
ngOnInit() {
}
}
错误显示
ERROR TypeError: co._router.generate is not a function
ALse webstorm generates an error that
unkwon method router is active
有什么问题吗?
只需为此使用 RouterLinkActive 指令:
https://angular.io/docs/ts/latest/api/router/index/RouterLinkActive-directive.html
它已经在 @angular/router
包中。