gpt4 book ai didi

angularjs - Uncaught Error : [$injector:cdep] use ngdialog in factory

转载 作者:行者123 更新时间:2023-12-02 04:46:26 25 4
gpt4 key购买 nike

我想使用 ngdialog 来处理 401 状态,但我收到错误:Uncaught Error: [$injector:cdep]

angular.module('ws.site.master', [
'ngResource',
'ngCookies',
'ngSanitize',
'ngAnimate',
'ui.router',
'ngDialog'
]);

我在这里添加了一个工厂来处理 401 状态。

angular.module('ws.site.master').factory('authHttpResponseInterceptor',['$q','$location','ngDialog',function($q,$location,ngDialog){
return {
response: function(response){
if (response.status === 401) {
console.log("Response 401");
}
return response || $q.when(response);
},
responseError: function(rejection) {
if (rejection.status === 401) {
console.log("Response Error 401",rejection);
ngDialog.open({
template: '/common/templates/at.modal.security.html',
className: 'ngdialog-theme-default modal-security',
closeByDocument: false,
closeByEscape: false,
trapFocus: false,
controller: ['$scope', function($scope) {
$scope.defaultView = defaultView || 'login';
}]
});
$rootScope.isSecurityModal = true;
}
return $q.reject(rejection);
}
}
}]);

此处将 authHttpResponseInterceptor 添加到 $httpProvider

angular.module('ws.site.master').config(['$stateProvider', '$urlRouterProvider', '$locationProvider', '$httpProvider', 'ROUTE',
function ($stateProvider, $urlRouterProvider, $locationProvider, $httpProvider, ROUTE) {
$locationProvider.html5Mode(true);
angular.forEach(ROUTE, function(_route, _name){
$stateProvider.state(_name, _route);
});
$urlRouterProvider.otherwise('/');
$httpProvider.interceptors.push('authHttpResponseInterceptor');
}
]);

最佳答案

错误:$injector:cdep - 循环依赖

请查看有关 this 的 Angular 文档

angular.module('myApp', [])
.factory('myService', function (myService) {
// ...
})
.controller('MyCtrl', function ($scope, myService) {
// ...
});

你两次注入(inject)“ngDialog”,先是你的主模块,然后是工厂,所有这些都在同一个“ws.site.master”中

关于angularjs - Uncaught Error : [$injector:cdep] use ngdialog in factory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32561443/

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