I'm running into some odd behavior when putting an ngInclude inside an ngIf or ngSwitch.

For example, take the following:

<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)

The buttons toggle an options to render the divs that follow. The inline example behaves as expected, with the content appearing or disappearing on click.

The div with the child include seems not to include the template when first drawn, but then includes it repeatedly on every subsequent redraw.

What's going on here? I do see some breaking changes around ngInclude, is there some other way I should be doing this? Or is this a bug in Angular?

Edit:

It looks like this is already in the angularjs github issue tracker: https://github.com/angular/angular.js/issues/3627

有帮助吗?

解决方案

They've fixed it in this snapshot:

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top