jmealy
jmealy

Reputation: 592

When using AngularJS's $timeout, what's the default delay?

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?

Upvotes: 7

Views: 8948

Answers (4)

Tim Hong
Tim Hong

Reputation: 2764

The default delay is 0. The documentation has been updated since.

offical angularjs $timeout doc

Upvotes: 2

DanArl
DanArl

Reputation: 1143

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';
            });
        });

Upvotes: 2

kubuntu
kubuntu

Reputation: 2535

When $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

Upvotes: 9

Joel Skrepnek
Joel Skrepnek

Reputation: 1661

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.

Upvotes: 7

Related Questions