forked from angular/angular.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbadprom.ngdoc
25 lines (20 loc) · 906 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 $timeout:badprom
@fullName Non-$timeout promise
@description
This error occurs when calling {@link ng.$timeout#cancel $timeout.cancel()} with a promise that
was not generated by the {@link ng.$timeout $timeout} 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.$timeout#cancel $timeout.cancel()}.
Example of incorrect usage that leads to this error:
```js
var promise = $timeout(doSomething, 1000).then(doSomethingElse);
$timeout.cancel(promise);
```
To fix the example above, keep a reference to the promise returned by
{@link ng.$timeout $timeout()} and pass that to {@link ng.$timeout#cancel $timeout.cancel()}:
```js
var promise = $timeout(doSomething, 1000);
var newPromise = promise.then(doSomethingElse);
$timeout.cancel(promise);
```