It's not that much.
When I create a menu in Angular, on each item I will have a "select" function, which then selects this particular object from the list ...
Creating an iterative button is even smoother:
var i = 0; $scope.states[ { text : "Active" }, { text : "Inactive" }, { text : "Excluded" } ]; $scope.currentState = $scope.states[i]; $scope.cycleState = function () { i = (i + 1) % $scope.states.length; $scope.currentState = $scope.states[i];
The actual array of states would not even have to be part of $scope
here, if it were the only place you used these objects - the only object that you would need to have on $scope
would then be the currentState
that you set when you call the cycleState
method.
source share