My query pertains specifically to Angular/Typescript. I have an array containing elements that I am displaying on an HTML page, but the code is not finalized yet. Here is an excerpt:
Typescript
import { Component, Input, NgZone, OnInit } from '@angular/core';
...
@Component({
selector: '...',
templateUrl: '...'
})
export class MyComponent implements OnInit {
...
staticKpi = [];
constructor(...) {
super();
}
ngOnInit(): void {
this.initializeComponent();
}
private initializeComponent() {
let row = []; // For example, Apple, Banana, Mango, etc
...
// GET CALL TO AN API TO POPULATE row[]
...
this.staticKpi.push(row); // <--- THIS I WANT TO CLEAR AFTERWARDS
row=[]; // CLEAR THE ARRAY
}
}
HTML/Template
<div *ngFor="let element of staticKpi">
<h2>element</h2>
</div>
Once staticKpi
has been rendered, I aim to reset the array so it is primed for the next GET call, as opposed to accumulating additional elements on top of the existing ones. However, currently, nothing is being displayed. I suspect that the array may be getting cleared immediately after being populated. Can you identify where I might be going wrong?