Forms 如何对所有窗体控件禁用emitEvent
是否有方法将所有窗体控件的emitEvent设置为false 目前,当我们修补Value或setValue时,可以传递选项以不引发窗体的valueChanges:Forms 如何对所有窗体控件禁用emitEvent,forms,angular,Forms,Angular,是否有方法将所有窗体控件的emitEvent设置为false 目前,当我们修补Value或setValue时,可以传递选项以不引发窗体的valueChanges: form.get['myControlName'].setValue('newValue', {emitEvent:false}) form.get['myControlName'].patchValue('newValue', {emitEvent:false}) 但是如果我们有很多patchValue或setValue,它有点重
form.get['myControlName'].setValue('newValue', {emitEvent:false})
form.get['myControlName'].patchValue('newValue', {emitEvent:false})
但是如果我们有很多patchValue或setValue,它有点重复。。。我有办法在之前禁用emitEvent,更改所有值并在之后再次激活它?您可以使用如下简单解决方案: 迭代窗体的所有控件并重置其值,然后将
emitEvent
设置为false
:
//the "manual" solution :
form.controls['name'].setValue('nameNewValue', {emitEvent:false});
form.controls['address'].setValue('addressNewValue', {emitEvent:false});
// the "dynamic" solution
for(let control in form.controls){
form.controls[control].setValue(form.controls[control].value, {emitEvent:false});
}
希望有帮助:)