我如何不触发Angular 11中的onChange回调



在我的项目中,我使用registerOnChange方法通过输入字段中的每次更改来保存信息。但在特定的用例中,我不想从registerOnChange调用回调。I

这是我的代码的摘要

textInputControl: FormControl = new FormControl();
...
this.textInputControl.registerOnChange(() => {
this.textInputChangeHandler();
});
...
this.textInputControl.setValue("trigger the registerOnChange"); 
this.textInputControl.setValue("NOT trigger the registerOnChange").doNotTriggerOnChange(); // Hope the solution will something like this

尝试将{ emitEvent: false }作为第二个参数。

this.textInputControl.setValue("NOT trigger the registerOnChange", { emitEvent: false });

最新更新