I have a menu based on the following example:
<nav data-ng-controller="menuContrl" class="menuItem">
<a data-ng-class='{active:isActive("/{{item.path}}")}' data-ng-repeat="item in menu" href="#/{{item.path}}">
<span>{{item.title}}</span>
</a>
</nav>
item is an object, containing menu item information. Here is the JavaScript code for the directive and controller:
var app = angular.module("coolApp",[]);
function menuContrl($scope,$location){
$scope.menu=menu;
$scope.isActive = function(path){
return ($location.path()==path)
}
}
The problem is that ng-class
sets class
to active
only once during page rendering, but when you click on a menu items, nothing happenes. I suppose this is because the menu itself is not reloaded and I just change data inside <div>
. So how can I make it work without reloading the whole page?
ui-sref-active
see here – Runyon