Men*_*hak 3 javascript controller angularjs
我们正在尝试从AngularJS 1.0.7升级到1.2.1.在1.0.7中,我们能够将控制器设置为同一元素中的ng-include,就像这样
<div data-ng-include="'include1.html'" data-ng-controller="MyCtrl1"
Run Code Online (Sandbox Code Playgroud)
MyCtrl1将变得可用于内部的代码include1.html.
移动到我在此plunkr中说明的AngularJS 1.2.1时,这会中断.如果您将引用的版本更改为1.0.7,它将再次起作用.
我有兴趣了解发生了什么变化/为什么会这样.我试过搜索但找不到任何东西,或者我没有使用正确的条款.
另外,为我的ng-includes 指定控制器的正确方法是什么?
为什么不将ng-controller元素移动ng-include到模板内部:
index.html的:
<div data-ng-include="'include1.html'"></div>
<div data-ng-include="'include2.html'"></div>
Run Code Online (Sandbox Code Playgroud)
include1.html
<div data-ng-controller="MyCtrl1">
<h1>{{Username}}</h1>
</div>
Run Code Online (Sandbox Code Playgroud)
include2.html
<div data-ng-controller="MyCtrl2">
<h1>{{Username}}</h1>
</div>
Run Code Online (Sandbox Code Playgroud)
自Angular 1.2版以来,似乎ngController并ngInclude不能相互结合使用: