跳过程序中的值更改Angular 2控件的更改 [英] Skip programmatic changes in valueChanges of Angular 2 control
问题描述
我正在订阅Angular 2(2.2.1)控件的valueChanges
.它是在AbstractControl
的@angular \ forms \ src \ model.d.ts中定义的,并且它的文档字符串指出它将可以从UI以及程序化的UI中进行更改:
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})
另请参见
- https://angular.io/docs/ts/latest/api/forms/index/AbstractControl-class.html#!#setValue-anchor
- https://github .com/angular/angular/blob/e9f307f9488e44879dc027e5f4436fb6bc046fa4/modules/%40angular/forms/src/model.ts#L669
- https://angular.io/docs/ts/latest/api/forms/index/AbstractControl-class.html#!#setValue-anchor
- https://github.com/angular/angular/blob/e9f307f9488e44879dc027e5f4436fb6bc046fa4/modules/%40angular/forms/src/model.ts#L669
这篇关于跳过程序中的值更改Angular 2控件的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!