[英]How to apply active class in navigation if i used breadcrumb in angular js
I m learning to angular js and read some documents but i have face one problum . 我正在学习Angular JS和阅读一些文档,但是我面临一个问题。
HI im using a application with navigation as like this 嗨,我使用这样的导航应用程序
<ul class="nav navbar-nav">
<li ui-sref-active="active"><a ui-sref="dashboard.view">Dashboard</a></li>
<li ui-sref-active="active"><a ui-sref="aboutus">About</a></li>
<li ui-sref-active="active"><a ui-sref="contactus">Contact</a></li>
</ul>
Now my brodcrome is 现在我的直肠是
Home > About > Carrer My url is myxyz.com/#/aboutus/carrer
主页 > 关于 > Carrer我的网址是myxyz.com/#/aboutus/carrer
than active class is not apply About but if i click to About page than active class is add. 比活动班级不适用关于,但是如果我单击“关于”页面,则会添加活动班级。
Can u please tell me what I code write. 你能告诉我我写的代码吗?
Thanks . 谢谢 。
What I did on your case was I created a function inside a controller with couple of dependencies and then use ng-class
, 我对您的案例所做的工作是,我在具有几个依赖项的控制器内部创建了一个函数,然后使用ng-class
,
storeApp.controller('MyCtrl', function($scope, $location, $http) {
$scope.isActive = function(route) {
return route === $location.path();
}
And then used it in my navigation. 然后在我的导航中使用它。
<ul class="nav navbar-nav" ng-controller="MyCtrl">
<li class="hvr-underline-from-left">
<a ng-class="{activeClass:isActive('/store')}" href="#/store">SHOP</a>
</li>
<li class="hvr-underline-from-left">
<a ng-class="{activeClass:isActive('/category/0/0')}" href="#/category/0/0">COLLECTIONS</a>
</li>
</ul>
In this example, make sure you have declared activeClass or what ever class name you want in your CSS 在此示例中,确保已在CSS中声明了activeClass或想要的类名称
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.