Angular.JS Quiz Answer: The key to both is assigning the result of the function to a variable. To cleanup the timeout, just “.cancel()” it:
|
[crayon-675c638152bc5041434696 inline="true" class="language-js hljs"]<span class="hljs-keyword">var</span> customTimeout = $timeout(<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-params">()</span> {</span> <span class="hljs-comment">// arbitrary code</span> }, <span class="hljs-number">55</span>); $timeout.cancel(customTimeout); |
[/crayon] The same applies to “$interval()”. To disable a watch, just…