How to use a module in AngularJS?

7

I have the following code in AngularJS but I get the error:

  

Error: [$ injector: unpr] Unknown provider: AuthenticationProvider <   Authentication

My code is as follows:

app.js

angular.module('app')
.controller('HomeController', function ($scope, Authentication) {
    var usuario = { login : 'teste', senha : 'senha123'};
    $scope.usuario = Authentication.autenticar(usuario);
});

authentication.js

angular.module('api.Authentication', [
    'ngResource'
])
.factory('Authentication', ['$resource', function ($resource) {
    return $resource(endpoint + 'users/authentications', {}, {
        autenticar: { method: 'POST' }
    });
}]);

What's missing? Why does not it identify the factory Authentication ?

    
asked by anonymous 11.12.2013 / 17:35

2 answers

6

In part

 angular.module('app')
.controller('HomeController', function ($scope, Authentication) {
    var usuario = { login : 'teste', senha : 'senha123'};
    $scope.usuario = Authentication.autenticar(usuario);
});

Switch to

angular.module('app', ["api.Authentication"] )
.controller('HomeController', [
    "$scope",
    "Authentication",
    function ($scope, Authentication) {
        var usuario = { login : 'teste', senha : 'senha123'};
        $scope.usuario = Authentication.autenticar(usuario);
    }
]);
    
11.12.2013 / 17:42
1

Imported module api.Authentication is missing from file app.js

angular.module('app', [
   'api.Authentication'  
])
...

So the module is available for use.

    
11.12.2013 / 17:42