So I have a component which loads divs with animations. The divs are shown based on a datasource.
*note: In the example I'm using a lot of <any>
, that's because I've not decided the model yet.
apiService.ts
dataArray: Observable<Array<any>>;
constructor(){
this.getUpdateData();
setInterval(()=> this.getUpdateData(), 1000);
}
getUpdateData(){
this.httpClientCall()
.subscribe((response: any) => {
this.dataArray = response;
});
}
component.html
<div class="panels" *ngFor="let data of apiService.dataArray">
<div class="panel-that-has-animation">
{{ data.some_value_that_can_be_updated }}
</div>
</div>
Simple breakdown: I pull data from a remote location every minute, and let the response be the new data within dataArray
.
The problem that I'm having is that on each update, the whole panels
div's content gets replaced.
Where I'd rather just want to have the values updated instead of the entire div being re-rendered.
The array itself consists of objects, what I really like to do is update an object property within the array instead of replacing the entire array of objects. More precise; compare the 2 arrays and check if there are differences in the properties of the objects.
Example:
[
0: {id: 1, name: a, group: 'a'},
1: {id: 2, name: b, group: 'b'},
2: {id: 3, name: c, group: 'c'},
]
New data (from httpClient):
[
0: {id: 1, name: a, group: 'b'},
1: {id: 2, name: b, group: 'b'},
2: {id: 3, name: c, group: 'c'},
]
In the example, I'd like to update the first object in the array because the group string has changed, without replacing the entire array of objects.
I'm forever grateful with a why/how for the solution than just code that resolves this. Thank you in advance!