Angular's wrapper for window.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.cancel(promise)
.
In tests you can use $timeout.flush()
to synchronously flush the queue of deferred functions.
If you only want a promise that will be resolved after some specified delay then you can call $timeout
without the fn
function.
$timeout([fn], [delay], [invokeApply], [Pass]);
Param | Type | Details |
---|---|---|
fn (optional) | function()= | A function, whose execution should be delayed. |
delay (optional) | number | Delay in milliseconds. (default: 0) |
invokeApply (optional) | boolean | If set to (default: true) |
Pass (optional) | * | additional parameters to the executed function. |
Promise |
Promise that will be resolved when the timeout is reached. The promise will be resolved with the return value of the |
Cancels a task associated with the promise
. As a result of this, the promise will be resolved with a rejection.
Param | Type | Details |
---|---|---|
promise (optional) | Promise | Promise returned by the |
boolean |
Returns |
© 2010–2017 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://code.angularjs.org/1.5.11/docs/api/ng/service/$timeout