angular 8 定义的combineLatest流不生效,能帮着分析一下吗?
来源:5-7 实战复杂表单控件(下)

allen99
2019-11-23
angular 8 定义的流不生效,能帮着分析一下吗?
const age$ =Observable.prototype.pipe(
combineLatest(ageNum,ageUnit, ageUnit,ageUnit, (_n, _u) => {
return this.toDate({age: n, unit: u}
);
}),
map((d => {
return {date: d, from: ‘age’};
}
)),
filter( => this.form.get(‘age’).valid)
);
const merged$ = Observable.prototype.pipe(
merge(birthday,age, age,age),
filter( => this.form.valid));
this.sub = merged$.subscribe(d => {
const age = this.toAge(format(d.date,this.format));
console.log(d.from);
if (d.from === 'birthday') {
if(age.age !== ageNum.value) {
ageNum.patchValue(age.age, {emitEvent: false});
}
if(age.unit !== ageUnit.value) {
this.selectedUnit = age.unit;
ageUnit.patchValue(age.unit, {emitEvent: false});
}
this.propagateChange(d.date);
} else {
console.log('birthday.value : ' + birthday.value );
const ageToCompare = this.toAge(format(birthday.value,this.format));
if(age.age !== ageToCompare.age || age.unit !== ageToCompare.unit) {
birthday.patchValue(d.date, {emitEvent: false});
this.propagateChange(d.date);
}
}
}
写回答
1回答
-
接灰的电子产品
2019-11-24
直接用 combinelatest ,没有Observable.prototype.pipe 这种用法
00
Angular打造企业级协作平台,让你在Angular领域中出类拔萃
全网首个介绍官方 Material 组件库用法与 Redux 在 Angular 中的应用
998 学习 · 536 问题
相似问题