forked from angular/angular.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbadprom.ngdoc
25 lines (20 loc) · 928 Bytes
/
badprom.ngdoc
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
@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);
```