模块中的依赖项注入错误
Dependencies Injection error in modules
我有我的应用程序的模块:
angular.module('app', ['app.controllers','app.routes','app.services']);
我有我的服务模块:
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
}]);
我有我的控制器:
angular.module('app.controllers', ['app.services'])
.controller('meuCtrl',
['$scope','$rootScope','usuarioService','renderservice',
function($scope, $rootScope, usuarioService, renderService){
// logic of controller
}]);
但是对于 运行 应用程序,我得到依赖项注入错误:
Unknown provider: usuarioServiceProvider <- usuarioService <- meuCtrl
我不明白会发生什么,注射到适当的位置也是如此。
除非我做错了这些注射。
PS .: 所有 .JS 文件正在加载到 index.html,none 已被遗忘。
您的 usuarioService
工厂声明错误地将自身添加到 angular
对象的一个不存在的成员中。
你有:
angular.app('app.services', []) // note the 'app' usage
.factory('usuarioService', ['$rootScope', 'renderService',
你应该
angular.module('app.services', []) // note the 'module' usage
.factory('usuarioService', ['$rootScope', 'renderService',
试试这个
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
}]);
我有我的应用程序的模块:
angular.module('app', ['app.controllers','app.routes','app.services']);
我有我的服务模块:
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
}]);
我有我的控制器:
angular.module('app.controllers', ['app.services'])
.controller('meuCtrl',
['$scope','$rootScope','usuarioService','renderservice',
function($scope, $rootScope, usuarioService, renderService){
// logic of controller
}]);
但是对于 运行 应用程序,我得到依赖项注入错误:
Unknown provider: usuarioServiceProvider <- usuarioService <- meuCtrl
我不明白会发生什么,注射到适当的位置也是如此。
除非我做错了这些注射。
PS .: 所有 .JS 文件正在加载到 index.html,none 已被遗忘。
您的 usuarioService
工厂声明错误地将自身添加到 angular
对象的一个不存在的成员中。
你有:
angular.app('app.services', []) // note the 'app' usage
.factory('usuarioService', ['$rootScope', 'renderService',
你应该
angular.module('app.services', []) // note the 'module' usage
.factory('usuarioService', ['$rootScope', 'renderService',
试试这个
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
}]);