2016-09-20 104 views
0

我有我的主网页:角度引导活动菜单项

<li ng-class="{ active: hello.isActive('/page1')}"><a ui-sref="root.content({store:hello.store_selected,product:hello.product_selected})" >page1</a></li> 
    <li ng-class="{ active: hello.isActive('/page2')}"><a ui-sref="root.turnover({store:hello.store_selected,product:hello.product_selected})">page2</a></li> 

我有两个控制器,每个路由:Page1Controller和Page2Controller。我从中挑选代码的主页也有一个控制器:HelloController。 我有我的HelloController

vm.isActive= function(viewLocation){ 
    return viewLocation ===$location.path(); 
    }; 

当我点击一个项目我获得当前项目点亮。但我有两个问题:当我点击页面上的其他任何地方时,当前项目不再突出显示。并且在页面开始或刷新页面时,我没有突出显示的项目。 你能帮忙吗? 谢谢

+0

'

  • page1
  • ' 这应该可以解决您的问题。 – Pradeepb

    +0

    很好,它工作。谢谢。 – John

    回答

    0

    UI路由器已经有了这个功能内置在使用ui-sref-active

    <li ui-sfref-active="active"><a ui-sref="root.content({store:hello.store_selected,product:hello.product_selected})" >page1</a></li> 
    

    你的问题可能是路径没有一个绝对的比赛,你或许应该一直使用indexOf(),而不是检查平等