簡體   English   中英

Angular2將活動類分配給li標簽

[英]Angular2 assign active class to the li tag

我想在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包中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM