On the remarkably brief AngularJS $timeout documentation page, the 'delay' argument is stated as optional. When using $timeout without specifying a delay, I note that a delay is still applied.
Can anyone tell me how much time is allotted for the delay when the argument is left implicit?
On the remarkably brief AngularJS $timeout documentation page, the 'delay' argument is stated as optional. When using $timeout without specifying a delay, I note that a delay is still applied.
Can anyone tell me how much time is allotted for the delay when the argument is left implicit?
Share Improve this question edited Sep 11, 2018 at 10:18 Flip 6,7618 gold badges50 silver badges83 bronze badges asked Mar 8, 2014 at 1:34 jmealyjmealy 5921 gold badge5 silver badges15 bronze badges4 Answers
Reset to default 9When $timeout
delay is omitted, it defaults to 0
. However, the block of code contained in it is executed after the DOM has been manipulated by Angular. See response to AngularJS $evalAsync vs $timeout
My understanding is that a delay of '0' means that it will be picked-up as part of the next run of the event loop. That's an especially short but indeterminate amount of time.
It's immediately executed, the default would be zero. Here is a jsfiddle showing it: http://jsfiddle.net/dgarlitt/rqs3p/1/
angular
.module('myApp',[])
.controller('MyCtrl', function($scope, $timeout) {
$timeout(function() {
$scope.name = 'World';
});
});
The default delay is 0. The documentation has been updated since.
offical angularjs $timeout doc