By retrieving values from a database and displaying them using ng-repeat
within a div:
<div ng-controller = "myTest">
<div ng-repeat="name in names">
<h4>{{name.name}}</h4>
<button ng-class="{'active': isActive}" ng-click="test()" >me</button>
</div>
</div>
In the controller, there is:
$scope.test= function(){
$scope.isActive = !$scope.isActive;
}
A class called isActive is defined in the CSS file which is added or removed upon clicking the button. Due to the ng-repeat
, 5 result divs are created along with 5 buttons (one for each div). The issue arises when all 5 buttons receive the class change instead of just the clicked one. To achieve the desired behavior, only the clicked button should have the class applied/removed. How can this be resolved?