0

I want to show/hide a div with a navbar inside of it. Whenever the URL has /profile in it i want it to show the navbar. At this moment I have this:

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">

At this point it only shows the div when its :

www.randomwensite.com/profile

But when i go a page further its gone.

I want it showing whenever the whole URL contains /profile.

Like this: www.randomwebsite.com/profile/shop/edit

or: www.randomwebsite.com/profile/account

Any idea how I would be able to get that done?

hirse
  • 2,394
  • 1
  • 22
  • 24
  • Possible duplicate of [How to check if a string "StartsWith" another string?](http://stackoverflow.com/questions/646628/how-to-check-if-a-string-startswith-another-string) – Mistalis May 02 '17 at 13:22

1 Answers1

0

use indexOf to find a string in a string

app.controller('MainCtrl',['$scope', '$location', function($scope, $location) {
    $scope.isActive = function(viewLocation) {
        return   $location.path().indexOf(viewLocation);
    };
    $scope.$location = $location;
}]);
Sachila Ranawaka
  • 39,756
  • 7
  • 56
  • 80