为什么angular.bootstrap()文件抛出错误

时间:2016-05-20 11:31:50

标签: angularjs angular-bootstrap

我在此plunkr link

中有我的测试示例

我的问题不是this one

的重复

另外Google Result and Github Bug是关于错误记者没有定义他试图首先引导的模块

我有3个模块grandParentModuleparentModulenestedModule

我有引导parentModulenestedModule到2个嵌套div元素,它们正常工作。

但是一旦我尝试将grandParentModule引导到文档,就会出现控制台错误。

这是我的HTML

<div id="parent" ng-app="parentModule">
  <div id="nested">
  </div>
</div>

这是我的脚本

angular.module('grandParentModule', []);
angular.module('parentModule', []);
angular.module('nestedModule', []);

var nestedElem = document.getElementById("nested");

angular.bootstrap(angular.element(nestedElem), ['nestedModule']);

//comment / uncomment this line to toggle the error at console
angular.bootstrap(document, ['grandParentModule']);

只有这一行angular.bootstrap(document, ['grandParentModule']);导致错误

  

未捕获错误:[ng:btstrpd] http://errors.angularjs.org/1.5.5/ng/btstrpd?p0=%26lt%3Bdiv%20id%3D%22parent%22%20ng-app%3D%22parentModule%22%26gt%3B

有人可以向我解释为什么会这样吗?

1 个答案:

答案 0 :(得分:2)

这不是角度自举的工作原理。

你应该只引导一个模块。

如果使用多个独立模块,则不能嵌套引导它们的DOM元素。

此外,那些模块应该是什么?

如果他们被链接,那么他们之间必须有依赖关系,即:

angular.module('parentModule', ['grandParentModule']);

如果您希望使用自己的控制器拥有一些嵌套视图,请使用多个ng-controller或在网上查看ui-router

相关问题