问题描述
我正在使用java开发购物网站,我正在使用angurajs。
I am developing shoping website with java and I am using angurajs.
我对这个文件有问题:
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 :
未捕获错误:[$ injector:unpr]
$ injector / unpr?p0 = AuthenticationProvider%20%3C-%20Authentication
请有人帮我解决这个错误。
Please can somebody help me to solve this error.
推荐答案
看起来你正在使用两个 angular.module authApp & DashboardApp ,然后你应该通过注入 authApp c> c> c> c来获取你的服务 DashboardApp 模块code>进入它。
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.
var app = angular.module("DashboardApp", ["authApp"]);
假设 authApp 应该在这个地方进行初始化 angular.module('authApp',[])
Assuming authApp should be intialize somewhere like this angular.module('authApp',[])
这篇关于Angularjs未捕获错误:[$ injector:unpr]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!