I have a * ngFor that fills my html, and this data is fetched from an API, then I use schedule to reload the data every time it gives seconds = 15.
Only the data is being placed below the old one in HTML.
HTML
<p [class]="mainColor + ' teste' " *ngFor="let element of fil">Filial {{ element.FI }} = {{ element.porc }}</p>
TS:
ngOnInit() {
schedule.scheduleJob(' 15 * * * * * ', () => {
this.MetaService.FiliaisMetaDiarias().subscribe(
data => {
const response = (data as any)
this.objeto_retorno = JSON.parse(response._body);
this.objeto_retorno.forEach(element => {
this.tots = element.TOTAL
element.TOTAL = (element.TOTAL * 100).toFixed(3) + '%'
element.TOTAL = element.TOTAL.toString().replace(".", ",")
if (this.tots >= this.MetaAtingida) {
this.fil.push({
FI: element.FILIAL,
porc: element.TOTAL
});
this.mainColor = 'MetaAtingida'
}
});
}
Every time the second is = 15 it is reloaded and placed in the html, but it is not deleting the previous data that is in html.
Does anyone know how to solve this?