You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
NgFor with NgIf does not produce the correct results (Beta1) #6304
I am using NgFor on a <template> tag to render list items. Every iteration renders a list item. In addtion, every other iteration should render another list item (for every even index number, conditional with NgIf).
Have a look at this: http://codepen.io/tine2k/pen/ZQLZav?editors=001
Reproduce the bug by hitting the button several times and watch the wrong list item order. It should be "0, even number, 1, 2, even number, 3, 4, even number" and so on.
changed the title [-]NgFor with NgIf does not produce the correct results (Angular Beta)[/-][+]NgFor with NgIf does not produce the correct results (Beta0)[/+]on Jan 6, 2016
<template ngFor #item [ngForOf]="items" #i="index" #isEven="even" #isOdd="odd">
<li>{{i}}</li>
<li>{{isEven ? 'This number is even' : 'This number is not even'}}</li>
<li>{{isOdd ? 'This number is odd' : 'This number is not odd'}}</li>
</template>
This uses the internal NgFor properties and avoid the error message. But it is still weird that awful message when using some condition inside the <template> (probably it is related to nested <template>s?).
@ericmartinezr thanks for your help. In my real world example the if condition is more complex than even/odd. I simplified it to show the rendering bug.
changed the title [-]NgFor with NgIf does not produce the correct results (Beta0)[/-][+]NgFor with NgIf does not produce the correct results (Beta1)[/+]on Jan 17, 2016
Activity
[-]NgFor with NgIf does not produce the correct results (Angular Beta)[/-][+]NgFor with NgIf does not produce the correct results (Beta0)[/+]pe8ter commentedon Jan 6, 2016
What's really strange is that putting a space between the closing tags
</li></template>on line 8 fixes the problem in http://codepen.io/tine2k/pen/ZQLZav?editors=001tine2k commentedon Jan 6, 2016
Dude, what a fix! :)
tine2k commentedon Jan 6, 2016
Anyway, this still seems to be a real issue that has to be addressed.
pe8ter commentedon Jan 6, 2016
Definitely!
gsans commentedon Jan 6, 2016
Legendary way to approach bugs! Congrats =)
On 6 Jan 2016 22:20, "Peter Safranek" [email protected] wrote:
pe8ter commentedon Jan 9, 2016
This one is even more janked in Beta.1: http://plnkr.co/edit/ZWiQqw3nR8xS1MRrpTry?p=info
ericmartinezr commentedon Jan 9, 2016
@pe8ter you can always use
evenoroddpropertiesThis uses the internal NgFor properties and avoid the error message. But it is still weird that awful message when using some condition inside the
<template>(probably it is related to nested<template>s?).pe8ter commentedon Jan 9, 2016
Are nested templates off limits?
tine2k commentedon Jan 9, 2016
@ericmartinezr thanks for your help. In my real world example the if condition is more complex than even/odd. I simplified it to show the rendering bug.
tine2k commentedon Jan 10, 2016
@pe8ter see #6380
tine2k commentedon Jan 10, 2016
Updated my codepen example to Beta1. Still broken.
[-]NgFor with NgIf does not produce the correct results (Beta0)[/-][+]NgFor with NgIf does not produce the correct results (Beta1)[/+]tine2k commentedon Jan 30, 2016
Updated my codepen example to Beta2. Still broken.
tine2k commentedon Feb 3, 2016
Updated my codepen example to Beta3. Still broken.
3 remaining items
tbosch commentedon Feb 4, 2016
Thanks for reporting!
fix(core): support `ngFor` that has an `ngIf` as last node
tine2k commentedon Feb 15, 2016
Updated my codepen example to Beta6. Still broken.
warnerpinz commentedon Feb 18, 2016
How to use *ngIf with odd and even?
zoechi commentedon Feb 18, 2016
Have you tried
#6304 (comment)
with
`*ngIf="odd"
warnerpinz commentedon Feb 19, 2016
@zoechi Thanks for that. It's working now =)
tine2k commentedon Mar 3, 2016
Confirmed fixed in 2.0.0.Beta8. Thanks for the fix @tbosch !
angular-automatic-lock-bot commentedon Sep 8, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.