Feature: Cancel $http request
Use case is we started a new $http request, and therefore needs to cancel 1 or more previous $http requests.
Eg:
var previousPromises = []; previousPromises.push($http().then(function(){})); ...
Then: //previousPromises[0].cancel() or //previousPromises[0].reject()
Reference https://groups.google.com/forum/?fromgroups#!searchin/angular/cancel$20http/angular/aT-MowZoPJg/kPEr5Ja0GEwJ
A slightly related feature is ability to cancel a promise, or if the promise has a reference to the defer, then we can do promise.defered.reject();
i need this feature as well.
i have an interface where a user can quickly trigger many actions that in turn trigger $http requests. in the case that a request is triggered and one is currently waiting for a response, i would like to be able to cancel it before requesting the new one.
Me too, need that feature.
An alternative to enabling request cancellation would be to allow the client to optionally pass in a key for the request and $http would ensure that only one request per key is pending at any point in time. The latest request with a specific key would always trump prior requests with that key. $http would need to cancel any pending requests with the same key before sending the new request. If the key was falsy it would send the request without consideration for pending requests. In other words, any number of requests with falsy keys could be pending simultaneously. The promises for the cancelled requests could be rejected.
This solution would suit my use case very well, and I suspect others' use cases too, and it might also be simpler to implement because you would not need to change the promise interface.
+1 for this feature.
+1 from me as well
+1
+1
+1
+1
+1
@dbinit I think you should reject the promise when the abort method is called. The function that will handle the rejection can use the status parameter to find out if it was an abort request or different kind of error and then act consequently.
Need this feature! +1
+1
+1
+1
+1
dbinit's solution worked perfectly for me.
+1, @dbinit this new fix looks really nice!
another thing that i need is to be able to bind to the progress event of the xhr upload.
for example (in plain javascript):
var xhr = new XMLHttpRequest(); xhr.upload.addEventListener("progress", uploadProgress, false)
I want to be able to do the same thing by doing $http.post...
so maybe rather than just adding an abort method, it would be good to provide something that lets me just get at the original xhr object.