gpt4 book ai didi

angularjs - 注入(inject) $modal 到 httpProvider

转载 作者:行者123 更新时间:2023-12-04 16:34:52 25 4
gpt4 key购买 nike

我试图将 bootstrap $modal 注入(inject) httpProvider 以在模式中显示内部服务器错误消息 (500),但我收到循环依赖错误(发现循环依赖:$http <- $modal <- $http <- locale)

app.config(function($httpProvider) {
$httpProvider.interceptors.push(function ($q, $location, $modal) {
return {
'response': function (response) {
return response;
},
'responseError': function (rejection, modalInstance) {
if(rejection.status === 401) {
console.log('No permissions - redirected to the login page');
$location.path('/login');
} else if (rejection.status === 404) {
var modalInstance = $modal.open({
templateUrl: 'templates/modal/error.tpl.html',
controller: 'ModalController',
size: 'md',
resolve: {
object: function () {
return object;
}
}
});
}
return $q.reject(rejection);
}
};
});

有什么解决办法吗?

最佳答案

使用 $injector:

app.config(function($httpProvider) {
$httpProvider.interceptors.push(function ($q, $location, $injector) {
var modal = $injector.get("$modal");
modal.open ...

关于angularjs - 注入(inject) $modal 到 httpProvider,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29103416/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com