How can I toggle classes on several elements individually with ng-click?
In this question https://mcmap.net/q/451005/-angularjs-toggle-ng-class-ng-click toggling classes with a click was done like this:
CSS:
.red {
color: red;
}
JS:
$scope.toggle = false;
HTML:
<button id="btn" ng-click="toggle = !toggle" ng-class="{'red' : toggle}">Change Class</button>
But what if I have several buttons that each should toggle its own class with ng-click?
If I set it up in this way:
HTML:
<button id="btn" ng-click="toggle = !toggle" ng-class="{'red' : toggle}">Change Class</button>
<button id="btn2" ng-click="toggle = !toggle" ng-class="{'red' : toggle}">Change Class</button>
Both buttons get toggled if I press one.
I know a workaround is to define an own ng-click event for each button (f.ex toggle1 for button1, toggle2 for button2) - but is this the best way?