setTimout runs outside of angular. To do this, you need to use the $timeout service:
var app = angular.module('test', []); app.controller('TestCtrl', function ($scope, $timeout) { $scope.testValue = 0; $timeout(function() { console.log($scope.testValue++); }, 500); });
The reason is because two-way binding in angular uses dirty checking. This is a good article to read a dirty angular check. $scope.$apply() starts the $digest loop. This will apply the binding. $timeout handles $apply for you, so it is recommended that you use this function when using timeouts.
Essentially, the binding occurs during the $digest cycle (if the value is considered different).
Davin Tryon Nov 19 '13 at 11:19 2013-11-19 11:19
source share