问题描述
我有一个表格,只要控制输入值发生变化,它就会进行计算.
I have a form that do a computation whenever a control input value changes.
这是我的 form_group
外观:
form_group = this.fb.group({
control1: [],
control2: [],
control3: [],
...
control10: [],
});
我可以通过 form_group.valueChanges
观察到所有控件的值变化,并进行计算.但是我想排除一些不需要执行此操作的控件.
I can detect all controls value changes via form_group.valueChanges
observable, and do a computation. However i want to exclude some of the control that doesn't need to do such an action.
但是总有一种方法不检测特定控件上的更改吗?
编写 form_group.get('controlN').valueChanges
并在那里进行计算非常麻烦.我的表单中有5个或更多控件.
It is very burdensome to write a form_group.get('controlN').valueChanges
and do a computation there. I have 5 or more controls in my form.
推荐答案
您可以像这样将单个valueChanges Observables合并为一个:
You can merge individual valueChanges Observables into one like so :
Observable.merge(
[ control1.valueChanges,
control2.valueChanges ]
).subscribe(() => {
// do your computation
});
这篇关于如何观看除特定控件之外的所有FormControls ValueChanges?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!