Urularjs Uncaught error: [$ injector: unpr]

I am developing a shopping website with java and I am using angurajs.

I have a problem with these files:

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;
        }
    }
})

      

When I load the page in the browser, I get the error:

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

Please help me to solve this error.

+3


source to share


1 answer


It looks like you are using two angular.module

inside your application authApp

and DashboardApp

then you have to provide your service to the module DashboardApp

by injecting authApp

into it.

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

      



Assuming it authApp

should be initialized somewhere like thisangular.module('authApp',[])

+2


source







All Articles