Skip to content

Instantly share code, notes, and snippets.

@dguzzo
Last active August 29, 2015 14:20
Show Gist options
  • Save dguzzo/f7651045f6bf22fe4cc0 to your computer and use it in GitHub Desktop.
Save dguzzo/f7651045f6bf22fe4cc0 to your computer and use it in GitHub Desktop.
great way to cycle values via modulus operator
// see One-time Binding section in Angular docs,
// https://docs.angularjs.org/guide/expression
angular.module('oneTimeBidingExampleApp', []).
controller('EventController', ['$scope', function($scope) {
var counter = 0;
var names = ['Igor', 'Misko', 'Chirayu', 'Lucas'];
/*
* expose the event object to the scope
*/
$scope.clickMe = function(clickEvent) {
$scope.name = names[counter % names.length];
counter++;
};
}]);
<div ng-controller="EventController">
<button ng-click="clickMe($event)">Click Me</button>
<p id="one-time-binding-example">One time binding: {{::name}}</p>
<p id="normal-binding-example">Normal binding: {{name}}</p>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment