forked from angular/code.angularjs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathng.$interval.html
37 lines (37 loc) · 3.92 KB
/
ng.$interval.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<a href="http://github.com/angular/angular.js/tree/v1.2.3/src/ng/interval.js#L10" class="view-source btn btn-action"><i class="icon-zoom-in"> </i> View source</a><a href="http://github.com/angular/angular.js/edit/master/src/ng/interval.js" class="improve-docs btn btn-primary"><i class="icon-edit"> </i> Improve this doc</a><h1><code ng:non-bindable="">$interval</code>
<div><span class="hint">service in module <code ng:non-bindable="">ng</code>
</span>
</div>
</h1>
<div><h2 id="description">Description</h2>
<div class="description"><div class="ng-interval-page"><p>Angular's wrapper for <code>window.setInterval</code>. The <code>fn</code> function is executed every <code>delay</code>
milliseconds.</p>
<p>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 <code>count</code> iterations, or
run indefinitely if <code>count</code> is not defined. The value of the notification will be the
number of iterations that have run.
To cancel an interval, call <code>$interval.cancel(promise)</code>.</p>
<p>In tests you can use <a href="api/ngMock.$interval#methods_flush"><code>$interval.flush(millis)</code></a> to
move forward by <code>millis</code> milliseconds and trigger any functions scheduled to run in that
time.</p>
</div></div>
<h2 id="usage">Usage</h2>
<div class="usage"><pre class="prettyprint linenums">$interval(fn, delay[, count][, invokeApply]);</pre>
<h4 id="usage_parameters">Parameters</h4><table class="variables-matrix table table-bordered table-striped"><thead><tr><th>Param</th><th>Type</th><th>Details</th></tr></thead><tbody><tr><td>fn</td><td><a href="" class="label type-hint type-hint-function">function()</a></td><td><div class="ng-interval-page"><p>A function that should be called repeatedly.</p>
</div></td></tr><tr><td>delay</td><td><a href="" class="label type-hint type-hint-number">number</a></td><td><div class="ng-interval-page"><p>Number of milliseconds between each function call.</p>
</div></td></tr><tr><td>count <div><em>(optional)</em></div></td><td><a href="" class="label type-hint type-hint-number">number</a></td><td><div class="ng-interval-page"><p>Number of times to repeat. If not set, or 0, will repeat
indefinitely.</p>
</div> <p><em>(default: 0)</em></p></td></tr><tr><td>invokeApply <div><em>(optional)</em></div></td><td><a href="" class="label type-hint type-hint-boolean">boolean</a></td><td><div class="ng-interval-page"><p>If set to <code>false</code> skips model dirty checking, otherwise
will invoke <code>fn</code> within the <a href="api/ng.$rootScope.Scope#methods_$apply"><code>$apply</code></a> block.</p>
</div> <p><em>(default: true)</em></p></td></tr></tbody></table><h4 id="usage_returns">Returns</h4><table class="variables-matrix"><tr><td><a href="" class="label type-hint type-hint-promise">promise</a></td><td><div class="ng-interval-page"><p>A promise which will be notified on each iteration.</p>
</div></td></tr></table></div>
<div class="member method"><h2 id="methods">Methods</h2>
<ul class="methods"><li><h3 id="methods_cancel">cancel(promise)</h3>
<div class="cancel"><div class="ng-interval-cancel-page"><p>Cancels a task associated with the <code>promise</code>.</p>
</div><h5 id="methods_cancel_parameters">Parameters</h5><table class="variables-matrix table table-bordered table-striped"><thead><tr><th>Param</th><th>Type</th><th>Details</th></tr></thead><tbody><tr><td>promise</td><td><a href="" class="label type-hint type-hint-number">number</a></td><td><div class="ng-interval-cancel-page"><p>Promise returned by the <code>$interval</code> function.</p>
</div></td></tr></tbody></table><h5 id="methods_cancel_returns">Returns</h5><table class="variables-matrix"><tr><td><a href="" class="label type-hint type-hint-boolean">boolean</a></td><td><div class="ng-interval-cancel-page"><p>Returns <code>true</code> if the task was successfully canceled.</p>
</div></td></tr></table></div>
</li>
</ul>
</div>
</div>