跳过 Angular 2 控件的 valueChanges 中的编程更改 [英] Skip programmatic changes in valueChanges of Angular 2 control

查看:25
本文介绍了跳过 Angular 2 控件的 valueChanges 中的编程更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我订阅了 Angular 2 (2.2.1) 控件的 valueChanges 可观察对象.它在@angular\forms\src\model.d.ts 中的 AbstractControl 中定义,并且它的文档字符串指出它将从 UI 和程序化的改变 yiald:

I'm subscribing to the valueChanges observable of an Angular 2 (2.2.1) control. It's defined in AbstractControl in @angular\forms\src\model.d.ts and it's doc string states that it will yiald changes from the UI as well as programmatic ones:

/**
 * Emits an event every time the value of the control changes, in
 * the UI or programmatically.
 */
valueChanges: Observable<any>;

我如何过滤它以仅提供 UI 的更改而不是程序化的更改?

我认为布尔属性(原始的、脏的、触摸的等)对我无济于事,因为即使在控件被标记为脏之后 - 指示 UI 的更改,我想捕获 - 可能有是进一步的程序更改,我想忽略.

I think that the boolean props (pristine, dirty, touched, etc.) won't help me, because even after a control is marked dirty - indicating a change from the UI, which I would like to capture - there might be further programmatic changes, which I would like to ignore.

推荐答案

你可以使用

control.setValue(123, {emitEvent: false})

另见

这篇关于跳过 Angular 2 控件的 valueChanges 中的编程更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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