I have an *ngFor property in my Ionic-angular template which is printing all objects of an array property. The thing is that this array can change, having more elements or even updating some attributes for the already present objects. Because of that, I'm requesting to my server the array each 1 seconds using rxjs, subscribing it and reassigning the server response to the array property again.
Above mentioned has as result that the view is re rendered each second which causes that the data is appearing and dissapearing constantly on screen.
How is the best way to deal with that? I know that the way of updating the array is pushing the elements. However, as the old objects can change their properties values I don't know how to continue working.
I will show you some simplified code snnipets:
Interval subscription
import { interval } from 'rxjs';
private subscription;
simulationsResponse;
//data is the property for *ngFor
data;
public intervallTimer = interval(1000);
ionViewWillEnter() {
this.subscription = this.intervallTimer.subscribe(x => {
this.dm.getAllSimulations().then(res => {
this.simulationsResponse = res;
this.data = this.simulationsResponse.simulators;
});
});
}
Template
<div class="listSimulations" *ngFor="let simulation of data">
.
.
.
.
</div>