Monday, November 11, 2019

When handing an everchanging array into an Angular component as an Input, it may be wise to serialize and deserialize the array with every alteration.

Do something like the following to make sure the array has a new pointer every time is changes. That will keep the reference changing with the contents and allow change detection to pick up the changes. Otherwise the pointer does not change and nothing will proactively notice the guts beyond the pointer have been altered.

this.arrayChangingLocally.push(someChange);
this.arrayToHandOnwards = JSON.parse(JSON.stringify(this.arrayChangingLocally));

No comments:

Post a Comment