[英]Angular : http Interceptor is not getting injected in config block
我创建了一个简单的http拦截器,打算用来记录请求和响应。 问题是它在config块中未定义,该块首先执行并由于无法实例化哪个模块而引发错误。 下面是使用的代码:
authApp
.factory("httpInterceptor",function($log){
var httpInterceptor = {};
httpInterceptor.request = function(config){
$log.info("request is being made to " + config.url);
return config;
};
httpInterceptor.response = function(config){
$log.info("request to URL : " + config.url + " is completed
now.");
return config;
};
return httpInterceptor;
})
.config(function($httpProvider){
// Http Interceptor
$httpProvider.interceptors.push(httpInterceptor);
});
提前致谢 !!
您的代码似乎是正确的,除了要在其中$httpProvider
全新的拦截器到$httpProvider
的拦截器列表的特定行之外。
$httpProvider.interceptors.push(httpInterceptor);
该行不知道什么是httpInterceptor
,因为它被定义为角度工厂。 更改为
$httpProvider.interceptors.push('httpInterceptor'); // Note the quotes around it.
然后重试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.