Is it possible to update a FormArray based on the values of two other controls?
After thorough checks, TypeScript is indicating issues with 'st' and 'sp'.
The object is potentially null.
Can someone identify the errors in this code?
let starterChanges$ = of(null);
const starter = this.frm.get('starter');
if (starter) {
starterChanges$ = starter.valueChanges;
}
let spreadChanges$ = of(null);
const spread = this.frm.get('spread');
if (spread) {
spreadChanges$ = spread.valueChanges;
}
this.subscription.add(
combineLatest([starterChanges$, spreadChanges$]).subscribe(([st, sp]) => {
let current = 0;
if (st !== null && sp !== null) {
for (const control of this.orders.controls) {
if (!current) {
current = current + st + sp;
} else {
current = current + sp;
}
control.patchValue({ spread: current });
control.disable();
}
}
})
);