-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Nested transclusion not working with ng-repeat #7842
Comments
Please post a plunker with a minimum reproducible example, that would help the compiler gurus a lot. Thanks! |
I have edited the issue with 2 plunkers, one for v1.2.17 and another one for v1.2.18! |
Due to angular/angular.js#7842, we can't, for now, use Angular v1.2.18, as it is bugging the dropdown directive.
Just to clarify, I am not one of the compiler gurus. ;) but the problem also exists in the the latest beta: http://plnkr.co/edit/DW7NgK5LON3yYoM1O2No?p=preview ping @caitp @petebacondarwin |
Explanation:This code is working correctly. This is similar to #7874. What you are doing is actually a bit naughty :-) and not what transclusion is designed to do. Transcluded content by definition is supposed to be bound to the place in the DOM where it is originally found. In this case we have two transclusions:
The first transclusion is contents of the
The second transclusion is the contents of the
So in the transcluded elements we do not have access to the scope of the template, and so don't have access to the ng-repeat This worked previously because we had a bug in the compiler that actually bound nested transclusions incorrectly. Solution:The way to do this is not to use transclusion at all but to use the compile function of your directive to fix up your HTML correctly: http://plnkr.co/edit/lf4ZRsiiDrg2xfyWvJxI?p=preview
|
@petebacondarwin any tips for dealing with templates? |
OK, I managed to make it work now. |
If you want to use templates then you do indeed need |
As of Angular.js v1.2.18, nested transclusion with ng-repeat wasn't binding to the correct scope (see angular/angular.js#7842). To fix that, we should manually transclude the content of options and then, finally, compile the options with ng-repeat. Fixes #14
I was unsure because of doing |
Starting at 1382d4e, I'm no longer able to use a nested transclusion with
ng-repeat
.My use case is the following:
Both
parent
andchild
directives have transclude: true.parent
hasscope: true
, child hasscope: false
.items
attribute is replaced withng-repeat
after some parsing in the compile function.Something I noted while debugging in Batarang is that previously, I had a scope tree like this:
where 00A/00C had the
value
from the original array and 00B/00D were the content of each item in `ng-repeat.Now, my scope tree looks like this:
same rule applies.
Working plunker (with v1.2.17): http://plnkr.co/edit/tdbRdT8gnLKhdcGAWlNV
Reproducible plunker for v1.2.18: http://plnkr.co/edit/qA3tOaR5RyehjI02xGRW?p=preview
If I wasn't clear enough and any further info is needed, please let me know.
Thanks in advance.
The text was updated successfully, but these errors were encountered: