@@ -84,6 +84,7 @@ Watch [a video introduction of a talk I gave at Devoxx France](http://www.parley
|
84 | 84 | - [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) |
85 | 85 | - [Restangular fails with status code 0](#restangular-fails-with-status-code-0) |
86 | 86 | - [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) |
87 | 88 | - [Supported Angular versions](#supported-angular-versions) |
88 | 89 | - [Server Frameworks](#server-frameworks) |
89 | 90 | - [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
|
1306 | 1307 | |
1307 | 1308 | **[Back to top](#table-of-contents)** |
1308 | 1309 | |
| 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 | + |
1309 | 1328 | # Supported Angular versions |
1310 | 1329 | |
1311 | 1330 | Restangular supports all Angular versions from 1.0.X - 1.5.X |
|