我对模块声明和依赖注入感到有点困惑。
我理解simpler示例,但我正在寻找一种更具“命名空间”的可重用性方法。
使用this代码时,即使呈现代码,我仍然会收到错误Unknown provider: aServiceProvider <- aService
。
angular.module('myApp', ['testFactories', 'testServices']);
angular.module('testFactories', []);
angular.module('testFactories')
.factory('aFactory', function(){
return {
sayHello: function(text){
return "Factory says \"Hello " + text + "\"";
},
sayGoodbye: function(text){
return "Factory says \"Goodbye " + text + "\"";
}
}
});
angular.module('testServices', []);
angular.module('testServices')
.service('aService', function(){
this.sayHello = function(text){
return "Service says \"Hello " + text + "\"";
};
this.sayGoodbye = function(text){
return "Service says \"Goodbye " + text + "\"";
};
});
function HelloCtrl($scope, aService, aFactory) {
$scope.fromService = aService.sayHello("World");
$scope.fromFactory = aFactory.sayHello("World");
}
function GoodbyeCtrl($scope, aService, aFactory) {
$scope.fromService = aService.sayGoodbye("World");
$scope.fromFactory = aFactory.sayGoodbye("World");
}
angular.element(document).ready(function() {
angular.bootstrap(document);
});
问题是什么?
答案 0 :(得分:0)
您需要将myApp
声明为引导依赖项:
angular.bootstrap(document, ['myApp']);