I have an array that contains 40 positions. When doing a ngFor using this array, I create a series of components within that * ngFor. The problem is that it's putting an end to the performance. Debugging, and doing a counter within that, I found that it runs 600x, having only 40 items.
Reading on, I discovered that this is Change detection, but I could not solve it. Does anyone know how to circumvent this behavior? (I can not turn off the change detection).
In the .ts file
cont: number = 0;
array: number[] = [];
ngOnInit() {
let i = 0;
while(i < 40) {
this.array.push(i);
i++;
}
}
contador() {
console.log(this.cont);
this.cont++;
}
No html
<div *ngFor="let numb of array">
<!-- Imaginem aqui muitos outros componentes que executam várias funções -->
<p>{{ contador() }}</p>
</div>
Looking at the console, you'll see that the counter goes up to 400.
If you resize the screen, for example, it still continues to generate 400 more calls: