Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 346
jmealy Avatar asked Mar 08 '14 01:03

jmealy


People also ask

How does $Timeout work in AngularJS?

setTimeout . The fn function is wrapped into a try/catch block and delegates any exceptions to $exceptionHandler service. The return value of calling $timeout is a promise, which will be resolved when the delay has passed and the timeout function, if provided, is executed. To cancel a timeout request, call $timeout.

What is the difference between $timeout and setTimeout?

Angular $timeout is a wrapper written for window. setTimeout in form of a try catch block which throws exceptions via $exceptionHandler service. $timeout accepts the function to be delayed, delay time, a boolean to invoke $. apply and parameters to be passed to the function.

What is setTimeout in angular?

setTimeout() The global setTimeout() method sets a timer which executes a function or specified piece of code once the timer expires.

What is scope in Angular JS?

AngularJS Scope The scope is the binding part between the HTML (view) and the JavaScript (controller). The scope is an object with the available properties and methods. The scope is available for both the view and the controller.


2 Answers

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

like image 192
kubuntu Avatar answered Oct 21 '22 04:10

kubuntu


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.

like image 37
Joel Skrepnek Avatar answered Oct 21 '22 06:10

Joel Skrepnek