【发布时间】:2020-03-25 16:33:19
【问题描述】:
我有一个包含一堆字段的表单(使用 reactiveForm)。 当字段A或B的值发生变化时,我想执行doStuffWithAnB。
所以 combineLatest 似乎是我需要的。
combineLatest(A.valueChanges,B.valueChanges).subscribe(doStuffWithAnB)
现在如果用户进入表单,并且只触摸 B(或 A),我想执行我的功能,> 这里是 startWith
combineLatest(A.valueChanges.pipe(startWith(someDefaultValue),B.valueChanges.pipe(startWith(someOtherDefaultValue)).subscribe(doStuffWithAnB)
但现在 doStuffWithAnB 从一开始就被触发,因为我的 2 个流有一个 startWith,但我不想在其中一个字段被修改之前执行 doStuffWithAnB
我怎样才能以干净的方式实现这一目标?
【问题讨论】:
标签: angular rxjs angular-reactive-forms combinelatest