繁体   English   中英

在AngularJS 1.2中,如何为ng-include指定控制器?

[英]In AngularJS 1.2, how do I specify the controller for an ng-include?

我们正在尝试从AngularJS 1.0.7升级到1.2.1。 在1.0.7中,我们能够将控制器设置为同一元素中的ng-include,就像这样

<div data-ng-include="'include1.html'" data-ng-controller="MyCtrl1"

MyCtrl1将成为提供给内部的代码include1.html

移动到我在此plunkr中说明的AngularJS 1.2.1时, 这会中断 如果您将引用的版本更改为1.0.7,它将再次起作用

我有兴趣了解发生了什么变化/为什么会这样。 我试过搜索但找不到任何东西,或者我没有使用正确的条款。

另外,为ng-include s指定控制器的正确方法是什么?

为什么不将ng-controller从具有ng-include的元素移动到模板内部:

index.html的:

<div data-ng-include="'include1.html'"></div>    
<div data-ng-include="'include2.html'"></div>

include1.html

<div data-ng-controller="MyCtrl1">
    <h1>{{Username}}</h1>
</div>

include2.html

<div data-ng-controller="MyCtrl2">
    <h1>{{Username}}</h1>
</div>

从Angular 1.2版开始,似乎ngControllerngInclude不能相互结合使用:

问题1问题2问题3SO帖子

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM