检查给定字符串的URL

时间:2017-05-02 13:17:14

标签: angularjs angular-ui-router

我想在其中显示/隐藏带有导航栏的div。每当URL中包含/ profile时,我希望它显示导航栏。此刻我有这个:

JS

app.controller('MainCtrl',['$scope', '$location', function($scope, $location) {
    $scope.isActive = function(viewLocation) {
        return viewLocation === $location.path();
    };
    $scope.$location = $location;
}]);

HTML

<div ng-show="isActive('/profile')" ng-controller="MainCtrl">

此时它只显示div:

  

www.randomwensite.com/profile

但是当我进一步走了一页时,它就消失了。

我想在整个网址包含/个人资料时显示。

  

像这样:www.randomwebsite.com/profile/shop/edit

     

或:www.randomwebsite.com/profile/account

知道我怎么能做到这一点?

1 个答案:

答案 0 :(得分:0)

使用indexOf在字符串

中查找字符串
app.controller('MainCtrl',['$scope', '$location', function($scope, $location) {
    $scope.isActive = function(viewLocation) {
        return   $location.path().indexOf(viewLocation);
    };
    $scope.$location = $location;
}]);