In angular.js, $scope.greeting = xxx doesn't work in window.setTimeout. It has not any effect:
var myApp = angular.module('myApp', []);
myApp.controller('MyCtrl', function ($scope) {
$scope.greeting = 'init';
window.setTimeout(function () {
console.log('update greeting');
$scope.greeting = "hello"; // doesn't work here.
}, 3000);
})
Why?
The full comparison is below:
- It works (in ajax): http://jsfiddle.net/victorwoo/eDb2S/129/
- It doesn't work (in
window.setTimeout): http://jsfiddle.net/victorwoo/3b3s6ukp/2/