-
Notifications
You must be signed in to change notification settings - Fork 27.5k
ngRepeat + directive w/ templateUrl + ngIf = printed twice #6006
Comments
Weird! I'll take a look at this... It doesn't seem to be a regression (without bisecting, but it's present in every release since ngIf was introduced). So, thanks for catching this! |
I'm having trouble reproducing this exactly without ngRepeat (the way it works for you with a synchronous template, but not with an asynchronous template). It's very peculiar. I think it might be sort-of related to how |
I should add that |
Yeah, I just mean reproducing this in isolation from ngRepeat is a bit tricky... But I don't think it's really an issue with ngRepeat or ngIf, it's a bug with the compiler. ...OK, working reproduction without any builtins except ngIf http://plnkr.co/edit/diLpqXPHrDAjTzOVGH1L?p=preview ... The reason seems to be that the ngIfDirective's element is not the comment node which it should be expecting. Hm |
yeah, this looks like a valid issue in the compiler. @caitp can you please look into this? I can help if needed. |
Yeah, absolutely |
It seems that For non-asynchronous replace directives, I don't know if that's necessarily the issue, but it strikes me as an inconsistency worth investigating :> I'm not sure what the right criteria would be to tell it not to call |
hmmm I'm wrong, I don't think that's the issue with this. still poking through it. |
So, this is a tricky one to debug, I've been trying to generate a call graph by hand just to get a better overview of the difference between synchronous vs asynchronous behaviour. http://pygments.org/demo/223495/ << this is a diff, with good.txt being synchronous behaviour, and bad.txt being asynchronous behaviour. Of course I"m not logging every possible thing that's happening (having good static analysis tools in javascript would be really nice!) So, from the diff it's fairly easy to see what's happening, the child link functions would be called with the comment node in a synchronous mode, but are instead being called with a merged template of element nodes. I feel like changing this would probably break a lot of stuff, but it's worth a shot |
…h comment element Previously, element transclusion directives would not receive a comment node in their link functions when they were the root of an asynchronous replace template. This would cause duplicate elements to appear in an ng-if expression within ng-repeat. Closes angular#6006
…h comment element Previously, element transclusion directives would not receive a comment node in their link functions when they were the root of an asynchronous replace template. This would cause duplicate elements to appear in an ng-if expression within ng-repeat. Closes angular#6006
…h comment element Previously, element transclusion directives would not receive a comment node in their link functions when they were the root of an asynchronous replace template. This would cause duplicate elements to appear in an ng-if expression within ng-repeat. Closes angular#6006
…h comment element Previously, element transclusion directives would not receive a comment node in their link functions when they were the root of an asynchronous replace template. This would cause duplicate elements to appear in an ng-if expression within ng-repeat. Closes angular#6006
…h comment element Previously, element transclusion directives would not receive a comment node in their link functions when they were the root of an asynchronous replace template. This would cause duplicate elements to appear in an ng-if expression within ng-repeat. Closes angular#6006
…h comment element Previously, element transclusion directives would not receive a comment node in their link functions when they were the root of an asynchronous replace template. This would cause duplicate elements to appear in an ng-if expression within ng-repeat. Closes angular#6006
…h comment element Previously, element transclusion directives would not receive a comment node in their link functions when they were the root of an asynchronous replace template. This would cause duplicate elements to appear in an ng-if expression within ng-repeat. Closes angular#6006
Holy cow, lots of mentions to this issue, sorry about that ;) Anyways, this is fixed, it would be super helpful if you could help verify the solution just to make sure it doesn't break anything else. I know you have other things to do, but you know. |
… comment element This corrects a complicated compiler issue, described in detail below: Previously, if an element transclusion directive contained an asynchronous directive whose template contained another element transclusion directive, the inner element transclusion directive would be linked with the element, rather than the expected comment node. An example manifestation of this bug would look like so: ```html <div ng-repeat="i in [1,2,3,4,5]"> <div my-directive> </div> </div> ``` `my-directive` would be a replace directive, and its template would contain another element transclusion directive, like so: ```html <div ng-if="true">{{i}}</div> ``` ngIf would be linked with this template content, rather than the comment node, and the template element would be attached to the DOM, rather than the comment. As a result, this caused ng-if to duplicate the template when its expression evaluated to true. Closes angular#6006 Closes angular#6101
I'm seeing this using a third-party directive - the angularjs multiselect. anything I should do? I did hack it to use only the template vs the templateurl and it did stop the repetition but kind of broke the widget... |
I still see some problems with this scenario. I have this when using http://plnkr.co/edit/0KpEwgW8P2p00UfTYH6e?p=preview Also, when I tried the the output is
but the expected output should be:
|
A really weird case of an ng-repeat, a directive with an external template url and ng-if on root element leads to printing twice every directive.
Happens only with this combination.
Doesn't happen with regular template string, or if the ng-if not on the root element or not in an ng-repeat.
Source:
index.html
script.js
hello.html
Or here:
http://plnkr.co/edit/DmyCkta0G0mjzgMJvchk?p=preview
The text was updated successfully, but these errors were encountered: