现在我想用ng-class
切换课程,但现在我遇到了包含子<a>
的标签。这是 Html
<ul class="nav navbar-nav navbar-right">
<li ng-class="{active:isActive('/home')}"><a ui-sref='home'>Home</a>
</li>
<li ng-class="{active:isActive('/ebin'||'/reports')}" class="dropdown"><a href="" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Expenses<span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li><a ui-sref='ebin'>My Expenses</a>
</li>
<li><a ui-sref='reports'>Expense Reports</a>
</li>
</ul>
</li>
<li ng-class="{active:isActive('/settings')}"><a ui-sref='settings' translate="SETTINGS">Settings</a>
</li>
</ul>
JS部分:
$scope.isActive = function(route) {
return route === $location.path();
}
我这里的问题是ng-class
仅用于/ home和/ setting,但不适用于下拉菜单。任何想法?
答案 0 :(得分:1)
问题在于您传递的参数&#34; isActive(&#39; / ebin&#39; ||&#39; / reports&#39;)&#34;。这不是有效的字符串。
你能做的是:
ng-class="{'active':isActive('/ebin'), 'active':isActive('/reports')}"