7

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?

Flip
  • 6,233
  • 7
  • 46
  • 75
jmealy
  • 583
  • 1
  • 5
  • 14

4 Answers4

9

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

Community
  • 1
  • 1
kubuntu
  • 2,525
  • 1
  • 22
  • 24
7

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.

Joel Skrepnek
  • 1,651
  • 1
  • 13
  • 21
2

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';
            });
        });
DanArl
  • 1,113
  • 8
  • 10
2

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

offical angularjs $timeout doc

Tim Hong
  • 2,734
  • 20
  • 23