AngularJS 1.2 ng包含在ngIf内

时间:2013-08-19 22:07:28

标签: javascript angularjs angularjs-ng-include

将ngInclude放在ngIf或ngSwitch中时,我遇到了一些奇怪的行为。

例如,请执行以下操作:

<button ng-click="showIncTemplate = !showIncTemplate">Toggle Included Template</button>
<button ng-click="showInlineTemplate = !showInlineTemplate">Toggle Inline Template</button>

<div ng-if="showIncTemplate">
    <p>Included template:</p>
    <div ng-include="'template.html'"></div>
</div>

<div ng-if="showInlineTemplate">
    <h1>Inline Template</h1>
</div>

http://plnkr.co/edit/gULbwnKb0gQS8DWz0V6U

按钮切换选项以呈现后面的div。内联示例的行为与预期一致,内容在单击时显示或消失。

包含子项的div似乎在首次绘制时不包含模板,但在每次后续重绘时都会重复包含该模板。

这里发生了什么?我确实看到围绕ngInclude的一些重大变化,还有其他方式我应该这样做吗?或者这是Angular中的错误吗?

编辑:

看起来这已经在angularjs github问题跟踪器中: https://github.com/angular/angular.js/issues/3627

1 个答案:

答案 0 :(得分:5)

他们已在此快照中修复了它:

http://code.angularjs.org/snapshot/