3

I am developing shoping website with java and I am using angurajs.

I have problem with thise 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 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

Please can somebody help me to solve this error.

Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299
Mišel Ademi
  • 187
  • 4
  • 15

1 Answers1

2

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"]);

Assuming authApp should be intialize somewhere like this angular.module('authApp',[])

Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299
  • This soled the previous error, but now I get new error `Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.2.17/$injector/modulerr?p0=DashboardApp&p1=Er…gleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.17%2Fangular.min.js%3A18%3A203)` – Mišel Ademi Jun 28 '15 at 10:36
  • @MišelAdemi are you initializing `angular.module('authApp',[])` anywhere? – Pankaj Parkar Jun 28 '15 at 10:37
  • I changed this line `angular.module('authApp').service('Authentication', function Authentication($q, $http)` in this `angular.module('authApp', []).service('Authentication', function Authentication($q, $http)` – Mišel Ademi Jun 28 '15 at 10:38
  • @MišelAdemi this file should be loaded first before `DashboardControll.js` – Pankaj Parkar Jun 28 '15 at 10:40
  • @MišelAdemi but other way you could use `angular.module('DashboardApp').service` instead of `angular.module('authApp').service` – Pankaj Parkar Jun 28 '15 at 10:41
  • @MišelAdemi Glad glad to help you..Thanks do upvote :-) – Pankaj Parkar Jun 28 '15 at 10:44