我实际上正在实现一个HTTP拦截器,并且试图在内部使用自定义服务。但是我遇到了循环依赖性错误。
我的自定义服务非常简单,如果服务器响应错误,它只会向用户添加一条通知。
我想首先了解为什么会出现此错误以及如何避免此问题。
我的拦截器服务:
app.factory("authInterceptor",["$q","notification",function($q,notification){
return{
'responseError': function(response){
if(response.status === 401){ //Unhautorized (pas de token)
return $q.reject(response);
}else if(response.status === 403){
notification.show_fail(response.statusText)
return $q.reject(response);
}
}
}
}])
app.config(function($mdThemingProvider,$httpProvider){
$mdThemingProvider.theme("default")
.primaryPalette("red")
.accentPalette("orange");
$httpProvider.interceptors.push("authInterceptor");
})
这是我的自定义服务:
app.factory('notification',['$mdToast',function($mdToast){
var notification = {};
notification.show_fail = function(text){
var pinTo = notification.getToastPostion();
$mdToast.show(
$mdToast.simple({
hideDelay : 3000,
position : right,
content : text,
toastClass : "error"
})
)
return notification;
}])
这是我的错误:
找到循环依赖项:$ templateRequest <-$$ animateQueue <- $ animate <-$$ interimElement <-$ mdToast <-通知<- authInterceptor <-$ http <-$ templateRequest <-$ compile <-$ mdUtil <- $ mdTheming