我有一个非常简单的角度应用程序,我无法弄清楚出了什么问题。代码在plunkr上:http://plnkr.co/edit/QQkP2HB6VGv50KDdBPag?p=preview并生成错误:Uncaught Error:[$ injector:modulerr]由于以下原因无法实例化模块myApp: 错误:[$ injector:unpr]未知提供者:testService
代码在
之下<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>simple problem I can not figure out</title>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.js"></script>
<script type="text/javascript">
(function() {
'use strict';
var myAppModule = angular.module('myApp', []);
myAppModule.service('testService', function (testService) {
});
myAppModule.config(['testService',
function (testService) {
}]);
})();
</script>
</head>
<body >
<div ng-app="myApp">
<div>
myApp Here
</div>
</div>
</body>
</html>
答案 0 :(得分:2)
角度自举过程中有多个阶段。在配置阶段,你可以注入提供者。例如,您可以使用此代码:
myAppModule.config(['testServiceProvider',
function (testServiceProvider) {
}]);
要获取更多信息,请查看以下链接:
https://github.com/angular/angular.js/wiki/Understanding-Dependency-Injection#configuring-providers