本文介绍了纳克级condtionally和$位置路径角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里是我的地盘,例如: example.com 结果
和条件是:

here is my site for example : example.com
and the conditions are :

我想添加类时,用户在这些位置:结果
首先condiotion: example.com /# sRGB是的东西用户不点击喜欢的href =#结果链接
 和结果
第二: example.com/Cartable

i want to add class when user in these location :
First condiotion: example.com/# wihch is user click on something without link like href="#"
and
Second :example.com/Cartable

下面是我的一点code:

Here is my little code :

$scope.isActive = function (route) {
        return route === $location.path();

    }

HTML

ng-class="{cartable:isActive('/Cartable')}"

它的工作,但我怎么可以添加两个网址,像这样:

it's working , but how can i add two url , something like this:

ng-class="{cartable:isActive('/Cartable', '/#')}"

感谢

推荐答案

您有两种选择,要么加入多次调用isActive功能或条件如下:

You have two choices, either call the isActive function multiple times by adding a "or" condition as following:

ng-class="{cartable: isActive('/Cartable') || isActive('/#')}"

或改变isActive函数接受一个数组:

or changing the isActive function to accept an array:

$scope.isActive = function (routes) {
    angular.forEach(routes, function(route){
        if(route === $location.path())
            return true;
    });
}

这篇关于纳克级condtionally和$位置路径角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 11:08