ngRepeat together with ngInclude doesn't work (1.2.0rc1)
Hi,
When using the Angular 1.2.0rc1, elements with both ngRepeat and ngInclude does not seem to be repeated and included. E.g. <div ng-repeat="item in items" ng-include="'item.html'"></div>. This works in Angular 1.1.5, but nothing happens now.
See this Plunker: http://plnkr.co/edit/JFGw9CWhsAX4PgqCQneS
/Jacob
Conclusion
Please see bug summary and conclusion before posting further comments
Update
As of 1.2.0-rc.3 ngRepeat and ngInclude work together. Here is a demo: http://plnkr.co/edit/Yvd73HiFS8dXvpvpEeFu?p=preview
Possibly related issue: #3581
This was exactly the same code that made me open #3581. It's only that the example was already in the web so I rewrote it a little bit.
The issue is that new animations need a common element for adding/removing ngView/ngInclude into the DOM, since only a common element can be animated. It is therefore possible to have two ngViews in the DOM at the same time. The one just added, and the old one which is being animating away. This implies that ngView/ngInclude need to be able to make copies of themselves hence are transcluded elements. But our compiler can only deal with one transclusion per element so combining ngRepeat with ngInclude/ngView produces an error.
Unfortunately this is not something we can easily fix. So the only thing we can do is to provide a work around. Place ngRepeat an a parent element of ngView/ngInclude inserting extra div if necessary.
PS: This used to work in old animations, because we had a hack where the ng-animate would on children of ngView/ngInclude rather then on ngViwe/ngInclude itself. This hack is not possible with pure CSS animations.
@matsko
@mhevery The jsfiddle provided in issue #3581 has the ng-include as a child of the ng-repeat and it doesn't seem to work, if this is the same as the workaround you're suggesting.
I'm using ngInclude + ngRepeat to generate trees of items. LI's or TD's can't be wrapped inside other elements.
Also in this other example using the wrap work around and ngSwitch, when pressing "Set foo" or "Set bar" for the first time (and the template loads) the content is not showed. If you press foo & bar more times, the content it's continuously added one right below the old one, instead of deleting it.
http://plnkr.co/edit/M9E7Vn1BFSIknYuhcyhw?p=preview
If you change the script to 1.1.5 it works without any problems:
http://plnkr.co/edit/lo3CNp1s55hwYvzkwTZO?p=preview
Any descendant ng-include of the ng-repeat also does not work.
you can get around this by using a component:
before:
<div ng-repeat="a in b">
<ng-include src="'my-include.html'"></ng-include>
</div>
after:
html
<div ng-repeat="a in b">
<my-include></my-include>
</div>
js
angular.module("tickets").directive("myInclude", function() {
return {
restrict: "E",
templateUrl: "/my-include.html"
}
})
the descendant scenario is a different bug which is being addressed already by @matsko
Seems like a very common problem when nesting ngIf / ngTransclude or using templates and such.
@IgorMinar is there an issue logged for this somewhere which we can watch for updates?
Lets revisit this once https://github.com/angular/angular.js/pull/3649 is put in (the revert commits may have something todo with the transclusion bugs).
I hope you will do something about this issue. Please don't introduce any backward incompatible changes just because of some internal refactoring reason :)
@mhevery, @symblify Here is another simple example of include not working inside other directives like switch, repeat, etc (nested, not combined):
1.1.5: http://jsfiddle.net/YSzxN/4/
1.2.0rc1 http://jsfiddle.net/YSzxN/5/
@dkingsbury This might be a problem with transclusion.
I've build angular.js using the code as of yesterday (21.08.2013) and seems like it's been fixed (changes reverted) (at least for ngInclude+ngTemplate) Don't know if it's final or temporary solution.
See latest commits for more info.
Tested this with the latest build (last commit is 99175f4294) and now my includes inside templates work again. Awesome.
@kevin-smets works for me as well, however the recent change broke the ng-show when used on the same element as ng-include. Element with ng-show="false" is visible, but shouldn't.
I have tried current snapshot (v1.2.0-6b91aa0) and ng-include="'some_templ.html'" ng-show="false" always shows the element. It works fine in version 1.2rc1.
See plunker: http://plnkr.co/edit/5mjPnXNydIcaOoa8KXAN
@kevin-smets : the "ng-repeat ng-include" pattern was broken since v.1.2.0rc1. Now using the last snapshot (v1.2.0-e86de0d), it works again for me too. Thanks !
<div ng-if="true" ng-view></div> is this supposed to be working?
Latest build works for me also.
Incorrect work ngRepeat + ngInclude: http://plnkr.co/edit/f7ra510tFqV6kruFnJWg?p=preview If we wouldn't fix it, add notice about extra element and my example in documentation
Latest snapshot (f737c97) fixed this for me too. Living on the bleeding edge.