Skip to content

Instantly share code, notes, and snippets.

@whisher
Created November 22, 2019 09:59
Show Gist options
  • Save whisher/5bc53200f95c6a270c11eae0ce559d65 to your computer and use it in GitHub Desktop.
Save whisher/5bc53200f95c6a270c11eae0ce559d65 to your computer and use it in GitHub Desktop.
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 = 0, sp = 0]) => {
let current = 0;
if (typeof st === 'number' && typeof sp === 'number') {
for (const control of this.orders.controls) {
if (!current) {
current = current + st + sp;
} else {
current = current + sp;
}
control.patchValue({ spread: current });
control.disable();
}
}
}
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment