Why *ngFor repeat for (array count) x 4 times ?
I have created simple Angular2 project using Angular-cli. I am using Angular4.
AppComponent (app.component.ts)
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
values = [1, 2, 3, 4, 5];
protected square(v) {
const retVal = v * v;
console.log(retVal, new Date().getMilliseconds());
return retVal;
}
}
app.component.html
<div *ngFor="let v of values">
<span>{{square(v)}}</span>
</div>
Result (rendered HTML)
Question ??
In HTML it is producing only 5 elements but when you look at console it is printing 20 times.
What I believe it should be only call square(v) for 5 times only not 20 times.