- service in module ng
Angular's wrapper for window.setInterval
. The fn
function is executed every delay
milliseconds.
The return value of registering an interval function is a promise. This promise will be notified upon each tick of the interval, and will be resolved after count
iterations, or run indefinitely if count
is not defined. The value of the notification will be the number of iterations that have run. To cancel an interval, call $interval.cancel(promise)
.
In tests you can use $interval.flush(millis)
to move forward by millis
milliseconds and trigger any functions scheduled to run in that time.
Usage
$interval(fn, delay, [count], [invokeApply], [Pass]);
Arguments
Param | Type | Details |
---|---|---|
fn | function() | A function that should be called repeatedly. |
delay | number | Number of milliseconds between each function call. |
count (optional) | number | Number of times to repeat. If not set, or 0, will repeat indefinitely. (default: 0) |
invokeApply (optional) | boolean | If set to (default: true) |
Pass (optional) | * | additional parameters to the executed function. |
Returns
promise |
A promise which will be notified on each iteration. |
Methods
-
cancel([promise]);
Cancels a task associated with the
promise
.Parameters
Param Type Details promise (optional)Promise
returned by the
$interval
function.Returns
boolean
Returns
true
if the task was successfully canceled.