简体   繁体   中英

How to trigger function every http request in angularjs

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.

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;
            }
        }
    });
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM