javascript - Angular route wildcard possible/workaround? -


i made isactive function set active class on menu element.

the function follow:

   $scope.isactive = function (path) {         if (path == $location.path()) {             return true;         } else {             return false;         }     } 

in html use:

   <li ng-class="{active: isactive('/page')}">    <a href="page">page</a></li> 

but html defined once in template. great use:

   isactive('/page*') 

so beyond '/page' url active state.

does knows workaround, because haven't found yet on forums , angular documention, guess isn't there yet..

possibly ?

$scope.isactive = function (path)  {      var strregexpattern = '\\b'+path+'\\b';       if( document.location.pathname.match(new regexp(strregexpattern,'g')) )     {         return true;     } else {         return false;     } } 

i don't know if can substitute

document.location.pathname.match(... // vanilla js 

with

$location.path().match(... // ng js 

...give try.


Comments