Angular1 - $interval

angular1

// Angular 1 - $interval

$interval is a wrapper for setInterval.

$interval(function() {
  $scope.itemIndex = Math.round(Math.random() * (items.length - 1));
  $scope.getItem();
}, 2000);

If we add the above code to our controller function, every 2 seconds, it will 
change the value for the itemIndex variable to some random value, and invoke 
the getItem function to update the value of the currentItem variable.

Because the itemIndex variable and the currentItem variable is already bound to 
the UI, via the ng-model attribute, and the double curly brace, when the above 
function is run every 2 seconds, the UI is automatically updated as well.
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License