简体   繁体   English

AngularJS $ http拦截器

[英]AngularJS $http interceptors

Javascript code... JavaScript代码...

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. 我认为该消息应该在xhr请求的开始处记录。 But I am seeing logs without xhr requests. 但是我看到没有xhr请求的日志。

Chrome Dev Tools屏幕截图

Am I misunderstanding the api? 我误会了api吗?

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/ 关于理解有角度的http拦截器,有一篇不错的博客文章,您可能会发现它很有用: http : //djds4rce.wordpress.com/2013/08/13/understanding-angular-http-interceptors/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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