How to watch all FormControls ValueChanges except specific control?
You can merge individual valueChanges Observables into one like so :
Observable.merge(
[ control1.valueChanges,
control2.valueChanges ]
).subscribe(() => {
// do your computation
});
Is there a reason why you couldn’t create a FormArray instead of multiple form controls? For example
form_group = this.fb.group({
'controls': this.fb.array([...])
});
Then you can define a property in your component
get controls(): FormArray {
return <FormArray>this.form_group.get('control');
}
And then from this you can iterate the form array and subscribe to valueChanges
this.controls.controls.forEach(control => {
control.valueChanges.subscribe(...)
});
You can then apply some logic in the for each to exclude the controls you do not want to subscribe to