Mr Hyde
Mr Hyde

Reputation: 3413

AngularJS $http interceptors

Javascript code...

commonApp = angular.module('commonApp') 
.config(function($httpProvider){
        $httpProvider.interceptors.push('myHttpInterceptor');
})
.factory('myHttpInterceptor', function($q, $window){
        return {
               request: function(config){
                       console.log('Request started'); // LOG AT REQUEST START
                       return config || $q.when(config);
                }
        };
 });

I believe that the message should be logged at the beginning of an xhr request. But I am seeing logs without xhr requests.

Chrome Dev Tools Screenshot

Am I misunderstanding the api?

Upvotes: 3

Views: 5518

Answers (1)

Jan Molak
Jan Molak

Reputation: 4526

Your plunkr seems to be working fine? There's a good blog post on understanding angular http interceptors you might find useful: http://djds4rce.wordpress.com/2013/08/13/understanding-angular-http-interceptors/

Upvotes: 4

Related Questions