Walter Gandarella
Walter Gandarella

Reputation: 858

Dependencies Injection error in modules

I have the module of my application:

angular.module('app', ['app.controllers','app.routes','app.services']);

I have my services module:

angular.app('app.services', [])
    .factory('usuarioService', ['$rootScope', 'renderService',
        function($rootScope, renderService){
            // logic of factory
    }]);

angular.module('app.services', [])
    .factory('renderService', ['$http',
        function($http){
            // logic of factory
    }]);

and I have my controller:

angular.module('app.controllers', ['app.services'])
    .controller('meuCtrl',
        ['$scope','$rootScope','usuarioService','renderservice',
            function($scope, $rootScope, usuarioService, renderService){
               // logic of controller
    }]);

But to run the application, I get dependencies injection error:

Unknown provider: usuarioServiceProvider <- usuarioService <- meuCtrl

I do not understand what might be going on, as do the injection into appropriate location.

unless I'm doing wrong these injections.

PS .: All .JS files are being loaded into index.html, none have been forgotten.

Upvotes: 0

Views: 949

Answers (2)

Wasiq Muhammad
Wasiq Muhammad

Reputation: 3118

Try this

angular.module('app.services')
    .factory('renderService', ['$http', function($http) {
        //logic
        return renderService;
}]);


angular.module('app.services')
    .factory('usuarioService', ['$rootScope', 'renderService',function($rootScope,renderService) {
        //logic
        return renderService;
}]);

angular.module('app.controllers', ['app.services'])
    .controller('meuCtrl',
        ['$scope','$rootScope','usuarioService','renderservice',
            function($scope, $rootScope, usuarioService, renderService){
               // logic of controller
    }]);

Upvotes: 1

mariocatch
mariocatch

Reputation: 8703

Your usuarioService factory declaration is incorrectly adding itself to a non-existent member of the angular object.

You have:

angular.app('app.services', []) // note the 'app' usage .factory('usuarioService', ['$rootScope', 'renderService',

You should have

angular.module('app.services', []) // note the 'module' usage .factory('usuarioService', ['$rootScope', 'renderService',

Upvotes: 1

Related Questions