angular/angular.js

View on GitHub
docs/content/error/$interval/badprom.ngdoc

Summary

Maintainability
Test Coverage
@ngdoc error
@name $interval:badprom
@fullName Non-$interval promise
@description

This error occurs when calling {@link ng.$interval#cancel $interval.cancel()} with a promise that
was not generated by the {@link ng.$interval $interval} service. This can, for example, happen when
calling {@link ng.$q#the-promise-api then()/catch()} on the returned promise, which creates a new
promise, and pass that new promise to {@link ng.$interval#cancel $interval.cancel()}.

Example of incorrect usage that leads to this error:

```js
var promise = $interval(doSomething, 1000, 5).then(doSomethingElse);
$interval.cancel(promise);
```

To fix the example above, keep a reference to the promise returned by
{@link ng.$interval $interval()} and pass that to {@link ng.$interval#cancel $interval.cancel()}:

```js
var promise = $interval(doSomething, 1000, 5);
var newPromise = promise.then(doSomethingElse);
$interval.cancel(promise);
```