I am looking for a way to "wrap" all $http requests so that I can display a gif image whenever the application does some processing. I also want to use the same solution to handle a different type, not just $http .
The reason I'm asking is because I always need to set my processingIndicator to true , and then go back to my success function, which is not elegant at all.
One potential solution I see is to use a function that takes a function as a parameter. This function will set processingIndicator to true , call the function, and then return processingIndicator to false.
function processAjaxRequestSuccessFn(fooFn){
And then
$http.get(...).then(processAjaxRequestSuccessFn, processAjaxRequestErrorFn)
This solution is not very convenient, because every time I need to notify the user that something is happening, I need to use this function.
I am looking for a way to automate this process.
Any other ideas?
Edit later
Another idea that I have is to extend $http with my own get , post , etc. Or create a custom service that has similar behavior. But still not very elegant.
source share