无法在angularjs中使用子模块

时间:2016-01-23 17:00:05

标签: angularjs

我创建了https://jsfiddle.net/5s126md5/3/

每个控制器都在不同的文件中。

为什么我这样做:[$injector:nomod] Module 'myApp' is not available!

实际上我有多个文件和不同的控制器

angular.module('myApp.controllers', []);

angular.module('myApp', [
    'myApp.controllers'
]);

angular.module('myApp.controllers')
    .controller('myController', function ($scope) {
        $scope.greeting = 'Hola!';
    });    

angular.module('myApp.controllers')
    .controller('AnotherController', function ($scope) {
        $scope.greeting = 'Hola! AnotherController';
    });

这是HTML:

  <body ng-app="myApp">
      <div ng-controller="myController">
      {{greeting}}
      </div>
   <div ng-controller="AnotherController">
        {{greeting}}
   </div>
    </body>

0 个答案:

没有答案