Hello,
I have a ng-repeat with a ng-class, to make the meny active when clicked. It adds the class ‘active’ to the selected menu, but the problem is that this keeping adding the active class to all menus I click and doesn’t remove the previous selected menu.
Here’s my JS:
$scope.getCategory = function(item) {
$scope.selected = item.name;
};
$scope.isActive = function(item) {
return $scope.selected === item.name;
};
Here’s the Html:
<li ng-repeat="category in categories" ng-controller="CategoryController">
<a ng-click="getCategory(category)" ng-class="{active:isActive(category)}">{{category.name}}</a>
</li>
Does someone know why is this happening? Thanks a lot