AngularJS [$喷油器:unpr]未知提供商 [英] AngularJS [$injector:unpr] Unknown provider
问题描述
我试图注入服务为控制器,而我收到以下错误:
I am trying to inject a service into controller, and i am getting following error:
Error: [$injector:unpr] Unknown provider: employeeServiceProvider <- employeeService
http://errors.angularjs.org/1.3.0-beta.17/$injector/unpr?p0=employeeServiceProvider%20%3C-%20employeeService
at http://localhost:9082/angularJSDemo/js/lib/angular.js:78:12
at http://localhost:9082/angularJSDemo/js/lib/angular.js:3894:19
at Object.getService [as get]
下面是 plunker 为code。任何帮助将是AP preciated。
Here is plunker for code. Any help would be appreciated.
推荐答案
您正在重复 angular.module('demoApp',[])
无处不在,将清除任何连接到已添加并重新创建模块,该模块的实体,模块的初始化后,你应该使用其引用或只是使用 angular.module('demoApp')。服务...
使用,这将检索模块,你可以加服等......
You are repeating angular.module('demoApp', [])
everywhere it will clear out any entities attached to the module that has been added already and recreate the module, after module initialization you should use its reference or just use angular.module('demoApp').service...
using this will retrieve the module to which you can add services etc...
var module = angular.module('demoApp', []).controller('employeeController', function($scope, employeeService) {
$scope.employees = employeeService.getData();
});
module.factory('employeeService', function (){
return {
getData : function(){
var employees = [{name: 'John Doe', id: '1'},
{name: 'Mary Homes', id: '2'},
{name: 'Chris Karl', id: '3'}
];
return employees;
}
};
});
Demo
报价从文件: -
要注意的是使用angular.module(MyModule的,[])将创建模块Mymodule中,并覆盖任何现有的名为MyModule的模块。使用angular.module('Mymodule中')来检索现有模块。
Beware that using angular.module('myModule', []) will create the module myModule and overwrite any existing module named myModule. Use angular.module('myModule') to retrieve an existing module.
这篇关于AngularJS [$喷油器:unpr]未知提供商的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!