I am trying to retrieve the input values from each row and then calculate the sum of these rows.
Here is my HTML code:
<ng-container formArrayName="cap_values">
<tbody *ngFor="let item of capValues.controls; let i=index" [formGroupName]="i">
<tr>
<td class="freeze-first-col"><input type="text" (blur)="getName(item.value.name)" formControlName="name"></td>
<td><input type="number" formControlName="fdnTotalShares"></td>
</tr>
</tbody>
</ng-container>
This is how my .ts file looks like:
ngOnInit() {
this.form = this.fb.group({
cap_values: this.fb.array([this.fb.group({
name: '',
fdnTotalShares: '',
}
)])
})
}
I'm looking for a way to loop through each value in the array and calculate the total sum. I've heard about using .valueChanges
, but I'm still not sure how to implement it properly.