gpt4 book ai didi

javascript - Angular 错误 : [ng:area] and [$injector:unpr] when import ngUpload

转载 作者:行者123 更新时间:2023-11-30 05:37:10 25 4
gpt4 key购买 nike

我正在尝试导入 Angular Directive(指令) ngUpload

但是当打开 html 页面时我有这个错误:

Error: [$injector:unpr] http://errors.angularjs.org/1.2.15-build.2378+sha.9335378/$injector/unpr?p0=AuthProvider%20%3C-%20Auth%20%3C-%20accessLevelDirective
http://localhost:8000/components/angular/angular.min.js:32:150
c@http://localhost:8000/components/angular/angular.min.js:30:201
http://localhost:8000/components/angular/angular.min.js:32:196
c@http://localhost:8000/components/angular/angular.min.js:30:201
d@http://localhost:8000/components/angular/angular.min.js:30:486
http://localhost:8000/components/angular/angular.min.js:40:166
forEach@[native code]

Error: [ng:areq] http://errors.angularjs.org/1.2.15-build.2378+sha.9335378/ng/areq?p0=NavCtrl&p1=not%20a%20function%2C%20got%20undefined
xb@http://localhost:8000/components/angular/angular.min.js:18:391
Pa@http://localhost:8000/components/angular/angular.min.js:18:449
http://localhost:8000/components/angular/angular.min.js:63:96
http://localhost:8000/components/angular/angular.min.js:49:196
r@http://localhost:8000/components/angular/angular.min.js:7:408
A@http://localhost:8000/components/angular/angular.min.js:49:62
h@http://localhost:8000/components/angular/angular.min.js:43:84
A@http://localhost:8000/components/angular/angular.min.js:49:468
h@http://localhost:8000/components/angular/angular.min.js:43:84

出现此错误的 Controller 是:

angular.module('angular-client-side-auth',['ngUpload'])
.controller('homeCtrl',
['$rootScope', '$scope', 'Users','$location', 'Auth', function($rootScope, $scope, Users,$location, Auth) {
$scope.isAdmin = function(){
console.log(JSON.stringify(Auth.user.role.title));
return Auth.user.role.title == "admin";
};
$scope.complete = function(content) {
console.log(content); // process content
};
Users.getMe(function(res) {
$scope.user= res;
}, function(err) {
$rootScope.error = "Failed to fetch me.";
$scope.loading = false;
});

}]);

有人知道吗?谢谢

------------更新------------

这是我的授权声明

angular.module('angular-client-side-auth')
.factory('Auth', function($http, $cookieStore){

var accessLevels = routingConfig.accessLevels
, userRoles = routingConfig.userRoles
, currentUser = $cookieStore.get('user') || { username: '', role: userRoles.public };

$cookieStore.remove('user');

function changeUser(user) {
angular.extend(currentUser, user);
};

return {
authorize: function(accessLevel, role) {
if(role === undefined)
role = currentUser.role;

return accessLevel.bitMask & role.bitMask;
},
isLoggedIn: function(user) {
if(user === undefined)
user = currentUser;
return user.role.title == userRoles.manager.title || user.role.title == userRoles.admin.title;
},
register: function(user, success, error) {
$http.post('/register', user).success(function(res) {
changeUser(res);
success();
}).error(error);
},
login: function(user, success, error) {
$http.post('/login', user).success(function(user){
changeUser(user);
success(user);
}).error(error);
},
logout: function(success, error) {
$http.post('/logout').success(function(){
changeUser({
username: '',
role: userRoles.public
});
success();
}).error(error);
},
accessLevels: accessLevels,
userRoles: userRoles,
user: currentUser
};
});

这是 NavCtrl 声明

angular.module('angular-client-side-auth')
.controller('NavCtrl', ['$rootScope', '$scope', '$location', 'Auth', function($rootScope, $scope, $location, Auth) {
$scope.user = Auth.user;
$scope.userRoles = Auth.userRoles;
$scope.accessLevels = Auth.accessLevels;

$scope.logout = function() {
Auth.logout(function() {
$location.path('/login');
}, function() {
$rootScope.error = "Failed to logout, sorry";

});
};
}]);

但如果我不导入 ngupload,我的 Angular 应用程序就没有任何问题

最佳答案

这看起来像是一个排序问题。

您需要先声明模块及其依赖项:

angular.module('angular-client-side-auth',['ngUpload']);

然后您需要在其他 Controller /服务/指令中使用它们之前添加您的其他 Controller 和服务:

angular.module('angular-client-side-auth').factory('Auth', ...);
angular.module('angular-client-side-auth').controller('homeCtrl', ...);
angular.module('angular-client-side-auth').controller('navCtrl', ...);

您试图在尚未注册 Auth 工厂的新声明模块上立即声明一个 Controller 。

关于javascript - Angular 错误 : [ng:area] and [$injector:unpr] when import ngUpload,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22985719/

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