使用{发射事件:假}的patchValue触发Angular 4表单组上的valueChanges [英] patchValue with { emitEvent: false } triggers valueChanges on Angular 4 formgroup

查看:64
本文介绍了使用{发射事件:假}的patchValue触发Angular 4表单组上的valueChanges的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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触发Angular 4表单组上的valueChanges的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆