Trying to calculate a total payOffs.amount (payOffs is a FormArray). Not sure how to do it properly so the total would observe changes to current and new for amounts. Here i
Or you could observe changes on the whole form array, by subscribing to the changes in the constructor.
this.form.controls.payOffs.valueChanges.subscribe((change) => {
const calculateAmount = (payoffs: any[]): number => {
return payoffs.reduce((acc, current) => {
// also handling case when a new pay off is added with amount of null
return acc + parseFloat(current.amount || 0);
}, 0);
}
console.log(calculateAmount(this.form.controls.payOffs.value));
});