I am searching for a solution to encapsulate all my AJAX requests using $http with the capability to display a loading gif image during processing. I want this functionality to extend beyond just $http requests, to cover other background processing tasks as well.
The reason for my inquiry is that it feels inelegant to constantly toggle my processingIndicator between true and false in my success function.
One potential approach I'm considering involves a higher-order function that takes another function as an argument. This function would set the processingIndicator to true, execute the provided function, and then switch back to false.
function processAjaxRequestSuccessFn(fooFn){
// display processing indicator
fooFn();
// hide processing indicator
}
Then I could use:
$http.get(...).then(processAjaxRequestSuccessFn, processAjaxRequestErrorFn)
This method, while effective, requires me to call the function every time I need to notify the user of processing actions, which is not very efficient.
I am exploring options to automate this workflow more seamlessly.
Update:
Another concept I am considering is extending $http with custom methods like get, post, etc., or creating a specialized service with similar functionality. However, these approaches also lack elegance.