When inside a transclusion, using replaceWith in a directive compile function doesn't work. #1367
Comments
+1 also having this problem. Were you able to find a fix? |
Not exactly a fix, but you can find more details on this thread - https://groups.google.com/d/msg/angular/GI50hYNe2yQ/wn-SqEuDWTIJ |
As part of our effort to clean out old issues, this issue is being automatically closed since it has been inactivite for over two months. Please try the newest versions of Angular ( Thanks! |
I faced the same issue when used Actually the replaced content was rendered instead of directive's root element, but it was not compiled at all ! No interpolation, no binding was done in result. The solution was not to replace, but to append the desired DOM to current directive' root within compile function and do actual DOM replacement in linking function. But this is not the desired hack, as it lowers performance if directive used along side with Used Angular |
+1 to seeing this problem, even though doing this in `link' works. |
I ran across a solution that allows you to use replaceWith and keep it in 'compile'. Just wrap the transcluded directive in another element... span, div, etc. and it just works. While it does work, the purpose of the extra element is not immediately obvious to someone else working with the code. So maybe use a more descriptive wrapping element? ? And... it would probably make sense to put a note in the comments of the directive that implements the replaceWith about the issue of using in it in conjunction with transclusion. Of course if the performance benefit of keeping it in compile is not great it may just be better to move it to 'link' as others have suggested. This workaround was originally suggested by Pete Bacon Darwin: Edit - It might be worth noting that this issue still persits in Angular 1.2.22 |
I've since opened another issue for this: #8710 |
yes, it was linked from this one automatically =P |
I'm using AngularJS 1.1.0 and I'm trying to modify the template structure of a directive to take some modifying attributes into consideration and I'm using .replaceWith to do so as I want to replace the original element.
That works fine until I use that directive inside another directive that uses ng-transclude. I suspect there's an issue related to the cloning done by the transclusion but I may also be doing something wrong.
Here's a fiddle to illustrate the problem: http://jsfiddle.net/passelin/Qt9Ey/
Thanks
The text was updated successfully, but these errors were encountered: