如何将Bootstrap导航栏设置为“活动" Angular 2中的课程? [英] How to set Bootstrap navbar "active" class in Angular 2?
本文介绍了如何将Bootstrap导航栏设置为“活动" Angular 2中的课程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Angular 2中设置Bootstrap导航栏活动"类?我只发现了角度1方式.
How can I set Bootstrap navbar "active" class in Angular 2? I only found Angular 1 way.
当我进入关于页面时,将class="active"
添加到关于,然后在主页上删除class="active"
.
When I go to About page, add class="active"
to About, and remove class="active"
on Home.
<ul class="nav navbar-nav">
<li class="active"><a [routerLink]="['Home']">Home</a></li>
<li><a [routerLink]="['About']">About</a></li></li>
</ul>
谢谢
推荐答案
如果使用新的3.0.0.组件路由器( https://github.com/angular/vladivostok ),您可以使用 routerLinkActive 指令.无需其他JavaScript.
If you use the new 3.0.0. component router ( https://github.com/angular/vladivostok ) you can use the routerLinkActive directive. No further javascript required.
<ul class="nav navbar-nav">
<li [routerLinkActive]="['active']"> <a [routerLink]="['one']">One</a></li>
<li [routerLinkActive]="['active']"> <a [routerLink]="['second']">Second</a></li>
</ul>
我使用了"@ angular/router":"^ 3.0.0-alpha.7"
I used "@angular/router": "^3.0.0-alpha.7"
这篇关于如何将Bootstrap导航栏设置为“活动" Angular 2中的课程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文