toppings : Array
toppings2 : Array我有两个订阅方法:
this.toppings.valueChanges.subscribe(val=> {
console.log(val);
}
this.toppings2.valueChanges.subscribe(val2=> {
console.log(val2);
}我想在相同的字体中使用val和val2。我怎样才能在同一个地方获得val和val2?(或val3= val+val2)
发布于 2018-09-04 17:27:04
zip组合了两个可观测值,并等待它们发出。combineLatest也会做得很好,你需要的并不重要,
zip(this.toppings.valueChanges, this.toppings2.valueChanges).subscribe(val => console.log(val[0] + val[1]))发布于 2018-09-04 17:26:44
combineLatest将为您提供最新版本的toppings和toppings2。
https://www.learnrxjs.io/operators/combination/combinelatest.html
大理石图:http://rxmarbles.com/#combineLatest
示例:
import {combineLatest} from 'rxjs';
combineLatest(this.toppings.valueChanges, this.toppings2.valueChanges )
.subscribe( ([topping1val, topping2val]) => {
let topping3 = topping1val + topping2val;
});https://stackoverflow.com/questions/52171218
复制相似问题