0

我对模块声明和依赖注入有点困惑。

我理解更简单的例子,但我正在寻找一种更“命名空间”的可重用性方法。

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);
});

有什么问题?

4

1 回答 1

0

您需要声明myApp为引导依赖项:

angular.bootstrap(document, ['myApp']);
于 2013-05-20T15:29:47.750 回答