1

I have an AngularJS HTTP interceptor:

$httpProvider.interceptors.push([
    "$rootScope", "$q", "$location",
    function ($rootScope, $q, $location) {

        return {
            'request': function (config) {
                var loc = $location.path();
                console.log("path: " + loc);
                ....
                ....
                return config;
            },
            ...
            };
        }
    ]);

I make a call that returns an array of 25 items. The items are populated into the html using ng-repeat. This display results in 75 calls to the request function.

Can anybody explain why it makes so many calls for one HTTP request?

Thanks for any help.

1 Answer 1

2

The http interceptor gets called for every request angular does, not just data requests. So also template requests, this might explain why it's so high.


Update: to filter out the templates I always use the following function.

function isLocalUrl(url) {
    return !(url.indexOf('http://') === 0 || url.indexOf('https://') === 0);
}

and call it like this:

return {
    'request': function (config) {
        if(isLocalUrl(config.url))
            return config;
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

That would explain it; is there any established pattern for working around this, and limiting the checks to just the data request?

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.