How to use a module in Angularjs?

Asked

Viewed 1,137 times

9

I have the following code in Angularjs but I have the error:

Error: [$injector:unpr] Unknown Provider: Authenticationprovider <- Authentication

My code is this:

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 doesn’t he identify Factory Authentication?

2 answers

8


In part

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

change to

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

1

Missing import of module api.Authentication in the archive app.js

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

Thus the module is available for use.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.