I have a service method that looks like:
this.myServiceFunction = function(){
var deferred = $q.defer();
$http({
method: 'GET',
url: 'domain/myendpoint'
})
.success(function(data){
deferred.resolve(data);
})
.error(function(data){
deferred.reject(data);
});
return deferred.promise;
};
I use this method in my controller in the following fashion:
$scope.myControllerFunction = function(){
myService.myServiceFunction().then(function(){
// Do things when promise resolves
});
};
I would like to cancel the HTTP call above in another function on command. I found this answer which allows you to cancel a HTTP request by calling the resolve()
method on the object returned from $q.defer()
. But in my codebase, this object is never made available in my controller.
myService.myServiceFunction()
in the example above returns a promise
object returned from $q.defer()
. How do I cancel my HTTP request within the confines of what I have?