繁体   English   中英

Angular Bootstrap活动菜单项

[英]Angular bootstrap active menu item

我在主页上:

  <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();
   };

当我单击一个项目时,我将当前项目突出显示。 但是我有两个问题:当我单击页面上的任何其他位置时,当前项目不再突出显示。 而且在页面开头或刷新页面时,我也没有突出显示item。 你能帮忙吗? 谢谢

ui-router已经使用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()而不是检查是否相等

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM