我想将活动类分配给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
可能出现什么问题?
答案 0 :(得分:1)
只需使用RouterLinkActive指令:
https://angular.io/docs/ts/latest/api/router/index/RouterLinkActive-directive.html
它已经在@angular/router
包中。