Injection error of module dependencies in angular

0

I have the module for 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){
            // logica do factory
    }]);

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

I have my controller:

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

But when I run the application, I get dependency injection error:

Unknown provider: usuarioServiceProvider <- usuarioService <- meuCtrl

I do not understand what may be happening, since I do the injection in every appropriate place.

Unless I'm making these wrong injections.

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

    
asked by anonymous 26.04.2016 / 21:38

2 answers

1

You are setting the app.services module twice.

When you pass the array of dependencies, angular creates a new module.

Without the array, it takes an existing module. Try removing [] in the second setting.

angular.module('app.services')
.factory('renderService', ['$http',
    function($http){
        // logica do factory
    }
]);
    
26.04.2016 / 22:52
1

In the way that you have declared the services, the second is overwriting the first, because when using the dependency injector "[]" inside the module, the angle creates a new module.

I suggest you try it that way.

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

var appServices = angular.module('app.services');

appServices.factory('usuarioService', ['$rootScope', 'renderService',
        function($rootScope, renderService){
            // logica do factory
    }]);

appServices.factory('renderService', ['$http', function($http){
            // logica do factory
    }]);
    
27.04.2016 / 14:36