[英]Angularjs Uncaught Error: [$injector:unpr]
I am developing shoping website with java and I am using angurajs. 我正在开发使用java的购物网站,我正在使用angurajs。
I have problem with thise files: 我有这个文件的问题:
DashboardControll.js DashboardControll.js
'use strict';
var app = angular.module("DashboardApp", []);
app.controller("DashboardCtrl", function($scope, $http, Authentication) {
$http.get("/SalonNamestaja/namestaj")
.success(function(response) {
$scope.namestaji = response;
});
$http.get("/SalonNamestaja/ActiveUser")
.success(function(response) {
//console.log(response);
$(".navbar-brand").empty();
$(".navbar-brand").append("Dobrodosli " + response.name);
$scope.activeUser = response;
});
console.log(Authentication.getUser());
});
app.run(function(Authentication) {
Authentication.requestUser();
});
Authentication.js Authentication.js
'use strict';
angular.module('authApp').service('Authentication', function Authentication($q, $http) {
var authenticatedUser = null;
return {
requestUser: function() {
var deferred = $q.defer();
$http.get("/SalonNamestaja/ActiveUser")
.success(function(user) {
console.log(user);
authenticatedUser = user;
deferred.resolve(user);
}).error(function(error) {
deferred.reject(error);
});
return deferred.promise;
},
getUser: function() {
return authenticatedUser;
},
exists: function() {
return authenticatedUser != null;
}
}
})
When I load page in browser I get the error : 当我在浏览器中加载页面时,我收到错误:
Uncaught Error: [$injector:unpr] http://errors.angularjs.org/1.2.17/ $injector/unpr?p0=AuthenticationProvider%20%3C-%20Authentication
未捕获错误:[$ injector:unpr] http://errors.angularjs.org/1.2.17/ $ injector / unpr?p0 = AuthenticationProvider%20%3C-%20身份验证
Please can somebody help me to solve this error. 请有人帮我解决这个错误。
Looks like you are using two angular.module
inside you application authApp
& DashboardApp
, then you should have make available your service to DashboardApp
module by inject authApp
into it. 看起来您在应用程序
authApp
和DashboardApp
中使用了两个angular.module
,然后您应该通过将authApp
注入其中来使您的服务可用于DashboardApp
模块。
var app = angular.module("DashboardApp", ["authApp"]);
Assuming authApp
should be intialize somewhere like this angular.module('authApp',[])
假设
authApp
应该像这个angular.module('authApp',[])
那样初始化
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.