Skip to content

NgFor with NgIf does not produce the correct results (Beta1) #6304

Closed

Description

@tine2k

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.

This works fine by hiding the list item using ngClass: http://codepen.io/tine2k/pen/bEqxBN?editors=001

Activity

  1. 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
  2. pe8ter commented on Jan 6, 2016

    @pe8ter

    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=001

  3. tine2k commented on Jan 6, 2016

    @tine2k
    Author

    Dude, what a fix! :)

  4. tine2k commented on Jan 6, 2016

    @tine2k
    Author

    Anyway, this still seems to be a real issue that has to be addressed.

  5. pe8ter commented on Jan 6, 2016

    @pe8ter

    Definitely!

  6. gsans commented on Jan 6, 2016

    @gsans
    Contributor

    Legendary way to approach bugs! Congrats =)
    On 6 Jan 2016 22:20, "Peter Safranek" [email protected] wrote:

    Definitely!

    —
    Reply to this email directly or view it on GitHub
    #6304 (comment).

  7. pe8ter commented on Jan 9, 2016

    @pe8ter

    This one is even more janked in Beta.1: http://plnkr.co/edit/ZWiQqw3nR8xS1MRrpTry?p=info

  8. ericmartinezr commented on Jan 9, 2016

    @ericmartinezr
    Contributor

    @pe8ter you can always use even or odd properties

    <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?).

  9. pe8ter commented on Jan 9, 2016

    @pe8ter

    Are nested templates off limits?

  10. tine2k commented on Jan 9, 2016

    @tine2k
    Author

    @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.

  11. tine2k commented on Jan 10, 2016

    @tine2k
    Author
  12. tine2k commented on Jan 10, 2016

    @tine2k
    Author

    Updated my codepen example to Beta1. Still broken.

  13. 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
  14. tine2k commented on Jan 30, 2016

    @tine2k
    Author

    Updated my codepen example to Beta2. Still broken.

  15. tine2k commented on Feb 3, 2016

    @tine2k
    Author

    Updated my codepen example to Beta3. Still broken.

  16. 3 remaining items

  17. modified the milestone: beta.03 on Feb 4, 2016
  18. tbosch commented on Feb 4, 2016

    @tbosch
    Contributor

    Thanks for reporting!

  19. added a commit that references this issue on Feb 11, 2016
    85a814b
  20. tine2k commented on Feb 15, 2016

    @tine2k
    Author

    Updated my codepen example to Beta6. Still broken.

  21. warnerpinz commented on Feb 18, 2016

    @warnerpinz

    How to use *ngIf with odd and even?

  22. zoechi commented on Feb 18, 2016

    @zoechi
    Contributor

    Have you tried
    #6304 (comment)
    with
    `*ngIf="odd"

  23. warnerpinz commented on Feb 19, 2016

    @warnerpinz

    @zoechi Thanks for that. It's working now =)

  24. tine2k commented on Mar 3, 2016

    @tine2k
    Author

    Confirmed fixed in 2.0.0.Beta8. Thanks for the fix @tbosch !

  25. angular-automatic-lock-bot commented on Sep 8, 2019

    @angular-automatic-lock-bot

    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.

  26. locked and limited conversation to collaborators on Sep 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions