I would like to pass an array of data to a child component. Depending on events in the child component the data may change:
HTML (parent):
<child-component [data]="array" (event)="updateArray()"/>
TypeScript (parent).
updateArray() {
...
this.array.push(more data)
...
}
The new data in the array should be re-rendered in the child component. But Angular does not regonize the changes.
I found a solution: https://chrislo.ca/angular-2345-change-detection-on-data-bound-array-pushunshift-popshift-or-splice/
pushAndUpdate(x) {
this.myArray = [...this.myArray, x];
}
It creates a new array.
My question is: is this the best way or is there something better?
OnPushchange detection strategy set on the child? That'd probably comes from there. BUT. To answer your question, working with immutable data is the way to go. (and keeping onpush..)