我有以下逻辑:
1.组件.ts
onChangeRow($event) {
form.controls["value"].patchValue($event.data.value, { emitEvent: false }); //
}
2.组件.ts
@Output() changeRow: EventEmitter<any> = new EventEmitter<any>();
this.formGroup.valueChanges.subscribe(data => {
this.changeRow.emit({selfRef: this.selfRef, form: this.formGroup, config: this.config})
})
看起来第一个组件中的 patchValue
方法触发了一个循环,因为它的新值被 valueChanges
捕获,并且循环继续,直到我获得 Maximum调用堆栈大小超出
错误。有时只触发 3 次,有时只触发一次。
我尝试理解为什么emitEvent 属性在这里不起作用。
最佳答案
尝试在 patchValue() 选项参数中将 onlySelf 设置为 true。
onChangeRow($event) {
form.controls["value"].patchValue($event.data.value, { onlySelf: true, emitEvent: false });
}
关于Angular Form Control 导致无限循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67179046/