patchValue 和 { emitEvent: false } 触发 Angular 4 表单组上的 valueChanges [英] patchValue with { emitEvent: false } triggers valueChanges on Angular 4 formgroup
问题描述
我有一个 formbuilder 组,正在监听 valueChanges 的更改并触发保存功能,然后是表单上的刷新功能:
I have a formbuilder group and am listening for changes with valueChanges and triggering a save function followed by refresh function on the form:
this.ticketForm.valueChanges.debounceTime(1000).distinctUntilChanged()
.subscribe(data => {
this.saveTicket();
this.refreshTicket();
})
然后我重新加载表单并将数据重新分配到带有 patchValue 的表单字段(以及页面上的其他地方,尤其是更改日志),例如:
I am then reloading the form and repatching the data to form fields (and elsewhere on the page, particularly a change log) with patchValue, e.g.:
this.ticketForm.patchValue(ticket, { emitEvent: false });
然而,这会导致表单保存的无限循环,尽管emitEvent : false.
however, this causes an infinite loop of saves of the form despite emitEvent : false.
这是 Angular 4/Ionic 3 的错误还是我的误解?
Is this an Angular 4/Ionic 3 bug or a misunderstanding on my part?
推荐答案
尝试以这种方式添加 onlySelf: true
和 emitEvent: false
:
Try adding onlySelf: true
along with the emitEvent: false
in this way:
this.ticketForm.patchValue(ticket, {emitEvent: false, onlySelf: true});
这篇关于patchValue 和 { emitEvent: false } 触发 Angular 4 表单组上的 valueChanges的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!