Reputation: 101
I just wanna know if we can add a function in every http request? ex.
$http.post('/Customer/FecthCustomer');
I mean all throughout the controller without putting the function each and every request there is.
I want to solve a problem where I cant get the page loaded event after the data from the server was fetch. PS(window.setTimeout, window.load, $(document).ready,angular.element(document)) TESTED and DID NOT work, they only trigger every single load of the page.
Upvotes: 1
Views: 416
Reputation: 101
Thanks to @holydragon!
Searched on interceptors.
Created this snippet:
angular.module('myModule', []).config(function($httpProvider) {
$httpProvider.interceptors.push(function($rootScope) {
return {
'request': function (config) {
console.log('REQUEST TRIGGERED');
return config;
}
}
});
})
Upvotes: 1