angular.js icon indicating copy to clipboard operation
angular.js copied to clipboard

ngRepeat together with ngInclude doesn't work (1.2.0rc1)

Open jafp opened this issue 13 years ago • 39 comments

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

jafp avatar Aug 14 '13 12:08 jafp

Possibly related issue: #3581

jafp avatar Aug 14 '13 12:08 jafp

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.

ernestoalejo avatar Aug 15 '13 07:08 ernestoalejo

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 avatar Aug 15 '13 21:08 mhevery

@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.

symblify avatar Aug 15 '13 21:08 symblify

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

ernestoalejo avatar Aug 15 '13 21:08 ernestoalejo

Any descendant ng-include of the ng-repeat also does not work.

istarkov avatar Aug 16 '13 02:08 istarkov

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

lhorie avatar Aug 16 '13 14:08 lhorie

the descendant scenario is a different bug which is being addressed already by @matsko

IgorMinar avatar Aug 17 '13 00:08 IgorMinar

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?

kevin-smets avatar Aug 19 '13 14:08 kevin-smets

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

matsko avatar Aug 19 '13 18:08 matsko

I hope you will do something about this issue. Please don't introduce any backward incompatible changes just because of some internal refactoring reason :)

janmarek avatar Aug 21 '13 20:08 janmarek

@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 avatar Aug 22 '13 15:08 dkingsbury

@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.

rtpm avatar Aug 22 '13 18:08 rtpm

Tested this with the latest build (last commit is 99175f4294) and now my includes inside templates work again. Awesome.

kevin-smets avatar Aug 22 '13 21:08 kevin-smets

@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

ognus avatar Aug 27 '13 10:08 ognus

@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 !

nderoche avatar Aug 28 '13 12:08 nderoche

<div ng-if="true" ng-view></div> is this supposed to be working?

cemo avatar Aug 28 '13 14:08 cemo

Latest build works for me also.

joaomvfsantos avatar Aug 29 '13 16:08 joaomvfsantos

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

tamtakoe avatar Sep 01 '13 09:09 tamtakoe

Latest snapshot (f737c97) fixed this for me too. Living on the bleeding edge.

gregtzar avatar Sep 03 '13 23:09 gregtzar