Here's some code : link
I'm trying to create a directive that wraps its children in some boilerplate. But if the children have ng-if
controlling their appearance, the "transclusion" doesn't work. Well it sort of does, but as you can see the ng-if
logic is not getting passed through correctly.
I'd like to know how to fix it, but also where (if anywhere) this is described in the Angular docs.
The problem is that Angular initially replaces
ngIf
with a comment that it uses to track where to place the conditional code. It's easiest to see with an example.Your HTML:
Looks like this inside your transclude function's
cloned
variable (transclude(function (cloned) {
):So, the element with class
text-error
that you're filtering on (below) isn't incloned
. Just the comment is there.Since you're only transcluding elements that match the above filter the
ngIf
comment is lost.The solution is to filter for comments as well and add them in your append (so Angular maintains it's reference point to the
ngIf
). One way to do that is to replace the above with this (using the fact that an html comment is node type 8)Working plunker