I am calling one method inside ngFor to get label of input its trigger for 8 times even in ngFor there is 2 item. It should be invoked for two times only. What could be the reason it is getting called for multiple times.
<form [formGroup]="parentForm">
<div formGroupName="child">
<ng-container *ngFor="let item of parentForm.get('child').controls | keyvalue; let i = index">
<div class="form-group">
<label>{{getLabel(item.key)}} {{i}} </label>
<input type="text" [formControlName]="item.key">
</div>
</ng-container>
</div>
</form>
getLabel(item) {
console.log('trigger item') // its get printed in console for 8 times
if(item == 'data') {
return 'Your Data'
}
return 'Your Name'
}
Playground: https://stackblitz.com/edit/angular-ivy-hnaegv?file=src%2Fapp%2Fapp.component.html