There's a much better/easier way to accomplish setting a active
CSS class. Just save a single value in your scope that holds the value of what is active. Something like this:
$scope.setActive = function (index) {
$scope.activeIndex = index;
};
Then ng-class
allows you to give it an map where "the names of the properties whose values are truthy will be added as css classes to the element" (From http://docs.angularjs.org/api/ng.directive:ngClass).
So you can set the CSS class if the $index
is the activeIndex
:
ng-class="{active: $index == activeIndex}"