在角多路径添加类 [英] adding class in multi path with Angular
本文介绍了在角多路径添加类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在这里是我的地盘,例如: example.com
结果
我能添加类时,路径是 example.com/Cartable
或路径是 example.com/requester
与这code:
here is my site for example : example.com
i'm able to add class when path is example.com/Cartable
or path is example.com/requester
with this code :
$scope.isActive = function (route) {
return route === $location.path();
}
HTML
ng-class="{cartable: isActive('/Cartable') || isActive('/requester')}"
但如没有在我的HTML一个按钮
but for example there is a button in my html with
<a href='#'>Click</a>
这是点击链接后为: example.com /#
所以这就是问题所在,
我不能这样code添加一个类:
that after click the url is: example.com/#
so that's the problem ,
i can't add a class with this code :
ng-class="{cartable: isActive('/Cartable') || isActive('/#')}"
任何想法?
推荐答案
您可以更改按钮的行为替换它是这样的:
You can change button behavior replacing it like this:
<a href="javascript:;">
这不会造成URL变化。
This will not cause url changing.
这篇关于在角多路径添加类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文