最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - When using AngularJS's $timeout, what's the default delay? - Stack Overflow

programmeradmin4浏览0评论

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 badges
Add a comment  | 

4 Answers 4

Reset to default 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

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

发布评论

评论列表(0)

  1. 暂无评论