AngularJS : can I stop a callback from an interceptor?
I have a $resource object that I am adding an interceptor to. I would like
to have the success callbacks not be called if certain conditions are met.
here is an example:
var service = $resource('/:action/:id', { id :'@id' });
service.interceptors.push(function() {
return {
response: function(response) {
if(response.data.red_flag) {
//stop execution here.
}
}
};
});
And then elsewhere in the code:
service.get({ id: 1}, function(response) {
//should not be called if response.data.red_flag is true
});
No comments:
Post a Comment