Podcast/lib/angular/docs/partials/api/ng.$timeout.html
2013-04-07 10:12:25 +02:00

52 lines
2.6 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<h1><code ng:non-bindable="">$timeout</code>
<span class="hint">(service in module <code ng:non-bindable="">ng</code>
)</span>
</h1>
<div><h2 id="Description">Description</h2>
<div class="description"><p>Angular's wrapper for <code>window.setTimeout</code>. The <code>fn</code> function is wrapped into a try/catch
block and delegates any exceptions to
<a href="api/ng.$exceptionHandler"><code>$exceptionHandler</code></a> service.</p>
<p>The return value of registering a timeout function is a promise which will be resolved when
the timeout is reached and the timeout function is executed.</p>
<p>To cancel a the timeout request, call <code>$timeout.cancel(promise)</code>.</p>
<p>In tests you can use <a href="api/ngMock.$timeout"><code>$timeout.flush()</code></a> to
synchronously flush the queue of deferred functions.</p></div>
<h2 id="Dependencies">Dependencies</h2>
<ul class="dependencies"><li><code ng:non-bindable=""><a href="api/ng.$browser">$browser</a></code>
</li>
</ul>
<h2 id="Usage">Usage</h2>
<div class="usage"><pre class="prettyprint linenums">$timeout(fn[, delay][, invokeApply]);</pre>
<h3 id="Parameters">Parameters</h3>
<ul class="parameters"><li><code ng:non-bindable="">fn {function()} </code>
<p>A function, who's execution should be delayed.</p></li>
<li><code ng:non-bindable="">delay<i>(optional=0)</i> {number=} </code>
<p>Delay in milliseconds.</p></li>
<li><code ng:non-bindable="">invokeApply<i>(optional=true)</i> {boolean=} </code>
<p>If set to false skips model dirty checking, otherwise
will invoke <code>fn</code> within the <a href="api/ng.$rootScope.Scope#$apply"><code>$apply</code></a> block.</p></li>
</ul>
<h3 id="Returns">Returns</h3>
<div class="returns"><code ng:non-bindable="">{Promise}</code>
<p>Promise that will be resolved when the timeout is reached. The value this
promise will be resolved with is the return value of the <code>fn</code> function.</p></div>
</div>
<div class="member method"><h2 id="Methods">Methods</h2>
<ul class="methods"><li><h3 id="cancel">cancel(promise)</h3>
<div class="cancel"><p>Cancels a task associated with the <code>promise</code>. As a result of this the promise will be
resolved with a rejection.</p><h4 id="Parameters">Parameters</h4>
<ul class="parameters"><li><code ng:non-bindable="">promise<i>(optional)</i> {Promise=} </code>
<p>Promise returned by the <code>$timeout</code> function.</p></li>
</ul>
<h4 id="Returns">Returns</h4>
<div class="returns"><code ng:non-bindable="">{boolean}</code>
<p>Returns <code>true</code> if the task hasn't executed yet and was successfully
canceled.</p></div>
</div>
</li>
</ul>
</div>
</div>