ngFor on Array of objects not updating DOM elements properly

3,693 views
Skip to first unread message

SLV SNZ

unread,
Oct 3, 2016, 11:13:28 AM10/3/16
to AngularJS
After I updated my angular 2 project from RC4 to 2.0.1 I'm having a problem with a ngFor looping on an array of objects (It was working fine on RC4) 

the list of elements is not being updated properly on the DOM, and now displayed unsorted .
the ngFor uses a pipe to slice the array (using the start and stop bounds).
the section displayed is updated each time we move the two bounds (start/ stop).


Steps to reproduce the bug /issue:
here is the plunkr:   https://embed.plnkr.co/aHIZKq/
  1. Move the start / stop bounds through the middle
  2. Then move the draggable bar to the left / right.  You'll see the elements displayed are being updated.
  3. At some point if you move to the left you'll see the elements being unsorted/mixed.
  4. I added on console log the id index from ngLoop. so you can see its unsorted when the problem occurs


I tried several changes on code, but nothing worked:
  • using a copy on the object
  • using an array with the keys...


thank you for your help

SLV SNZ

unread,
Oct 4, 2016, 5:25:46 AM10/4/16
to AngularJS
After checking angular 2 release updates I see where the problem comes from:
in RC5  --> "core: ensure ngFor only inserts/moves/removes elements when necessary"

I compared my projects RC4 and 2.0.1 and all elements are updated only in RC4 (as expected)

 there is a way to bypass this? and have all DOM elements updated after change in ngfor under 2.0.1 ??

SLV SNZ

unread,
Oct 10, 2016, 9:35:22 AM10/10/16
to AngularJS

Resolved:


In order to get all DOM elements/objects inside ngfor updated:

I had to create a new component, and then instanciate the component inside the ngFor.

now elements are properly updated as they were in RC4...

Marc-Antoine Roberge

unread,
Nov 10, 2016, 5:22:36 AM11/10/16
to Angular
can you post a plnkr of how you did it ?
Reply all
Reply to author
Forward
0 new messages