1

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.

1
  • Try searching with keyword "angularjs http interceptor". Commented Mar 21, 2019 at 1:53

1 Answer 1

1

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;
            }
        }
    });
})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.