Skip to content

Commit 8552c51

Browse files
committedDec 30, 2016
feat(docs) Add FAQ about cancelling request
Closes #926, closes #1145, closes #1377, closes #1391
1 parent 6883075 commit 8552c51

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed
 

Diff for: ‎.github/ISSUE_TEMPLATE.md

+5
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,8 @@ The project lacks resources to answer questions regarding general usage and prob
1717
* Please **enclose your code in [fenced blocks](https://help.github.com/articles/creating-and-highlighting-code-blocks/)** for readability.
1818

1919
The maintainers may opt to close issues that don't follow these guidelines.
20+
21+
**Also remember:**
22+
23+
* Pull requests fixing problems are highly appreciated ;)
24+

Diff for: ‎README.md

+19
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ Watch [a video introduction of a talk I gave at Devoxx France](http://www.parley
8484
- [How can I access the unrestangularized element as well as the restangularized one?](#how-can-i-access-the-unrestangularized-element-as-well-as-the-restangularized-one)
8585
- [Restangular fails with status code 0](#restangular-fails-with-status-code-0)
8686
- [Why does this depend on Lodash / Underscore?](#why-does-this-depend-on-lodash--underscore)
87+
- [How do I cancel a request?](#how-do-i-cancel-a-request)
8788
- [Supported Angular versions](#supported-angular-versions)
8889
- [Server Frameworks](#server-frameworks)
8990
- [Releases Notes](#releases-notes)
@@ -1306,6 +1307,24 @@ So, why not use it? If you've never heard of them, by using Restangular, you cou
13061307

13071308
**[Back to top](#table-of-contents)**
13081309

1310+
#### How do I cancel a request?
1311+
1312+
Sometimes you may wish to cancel a request, this is how you would do it:
1313+
1314+
```
1315+
var canceler = $q.defer();
1316+
Restangular.all('users').withHttpConfig({timeout: canceler.promise}).get();
1317+
canceler.resolve(); // cancels the request
1318+
```
1319+
1320+
This is a little counterintuitive, so let me explain. Restangular is built on top of `$http`, which takes a timeout parameter. As per the $http docs:
1321+
1322+
timeout in milliseconds, or promise that should abort the request when resolved.
1323+
1324+
Resolving the promise (canceler in this case), will cancel the request.
1325+
1326+
**[Back to top](#table-of-contents)**
1327+
13091328
# Supported Angular versions
13101329

13111330
Restangular supports all Angular versions from 1.0.X - 1.5.X

0 commit comments

Comments
 (0)