Angularjs Uncaught Error: [$injector:unpr]

Angularjs Uncaught Error: [$injector:unpr]

我正在使用 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;
        }
    }
})

当我在浏览器中加载页面时出现错误:

Uncaught Error: [$injector:unpr] http://errors.angularjs.org/1.2.17/$injector/unpr?p0=AuthenticationProvider%20%3C-%20Authentication

请有人帮我解决这个错误。

看起来您在应用程序 authAppDashboardApp 中使用了两个 angular.module,那么您应该通过注入 [=] 向 DashboardApp 模块提供服务12=]进入其中。

var app = angular.module("DashboardApp", ["authApp"]);

假设 authApp 应该像这样在某处初始化 angular.module('authApp',[])