My group of Boolean variables can toggle other variables to false when set to true.
I am looking for a clean pattern for this approach, especially since the number of boolean variables may increase.
angular.module("app", [])
.controller("controller", function($scope) {
$scope.a = true;
$scope.b = false;
$scope.c = false;
$scope.toggleA = function() {
$scope.a = true;
$scope.b = false;
$scope.c = false;
}
$scope.toggleB = function() {
$scope.b = true;
$scope.a = false;
$scope.c = false;
}
$scope.toggleC = function() {
$scope.c = true;
$scope.b = false;
$scope.a = false;
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="controller">
<button ng-click="toggleA()">A is {{a}}</button>
<button ng-click="toggleB()">B is {{b}}</button>
<button ng-click="toggleC()">C is {{c}}</button>
</div>