Reputation: 1991
I have a ajax call like this
angular.module('my.module')
.factory('Users', ['config', '$resource', function(config, $resource) {
return $resource('/my/endpoint', {
userId: '@userId'
}, {
query: {
method: "GET"
}
});
}])
then I have a UserLoader
.factory('UserLoader', ['Users', 'LoaderFactory', function(users, LoaderFactory) {
[some other stuff]
}])
and the the controller
.controller('UserSearchCtrl', ['$scope', 'UserLoader', function($scope, UserLoader) {
}])
how can I cancel a previous call before to send another?
Upvotes: 1
Views: 423
Reputation: 4050
You need to configure your resource as cancellable
query: {method: 'get',cancellable: true}
Then you can call $cancelRequest()
on this resource.
Users.query().$cancelRequest()
Upvotes: 1