AngularJS $ http拦截器 [英] AngularJS $http interceptors

查看:77
本文介绍了AngularJS $ http拦截器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JavaScript代码...

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

我认为应该在xhr请求的开头记录该消息. 但是我看到没有xhr请求的日志.

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

我误解了api吗?

推荐答案

您的plunkr看起来工作正常吗?关于了解有角度的http拦截器,您有一篇不错的博客文章,您可能会觉得有帮助: http://djds4rce.wordpress.com/2013/08/13/understanding-angular-http-interceptors/

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/

这篇关于AngularJS $ http拦截器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆