我正在使用Java开发购物网站,并且正在使用angurajs。
我对此文件有疑问:
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
'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;
}
}
})
当我在浏览器中加载页面时,出现错误:
请有人可以帮助我解决此错误。
最佳答案
看起来您在应用程序angular.module
和authApp
中使用了两个DashboardApp
,然后应该通过向其中注入(inject)DashboardApp
使服务对authApp
模块可用。
var app = angular.module("DashboardApp", ["authApp"]);
假设应将
authApp
初始化为此类angular.module('authApp',[])
关于javascript - Angularjs未捕获的错误:[$ injector:unpr],我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31098656/