Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 如何在RXJS 6中减去2个观测值_Angular_Rxjs_Angular6_Rxjs6_Combinelatest - Fatal编程技术网

Angular 如何在RXJS 6中减去2个观测值

Angular 如何在RXJS 6中减去2个观测值,angular,rxjs,angular6,rxjs6,combinelatest,Angular,Rxjs,Angular6,Rxjs6,Combinelatest,我想减去2个可观测的数字 this.num1:Observable<number> this.num2:Observable<number> this.num3:Observable<number> this.num1 = this.store.select(getNum1Count); this.num2 = this.store.select(getNum2Count); // this.num3 = difference of this.num1 an

我想减去2个可观测的数字

this.num1:Observable<number>
this.num2:Observable<number>
this.num3:Observable<number>

this.num1 = this.store.select(getNum1Count);
this.num2 = this.store.select(getNum2Count);
// this.num3 = difference of this.num1 and this.num2 
但是在RXJS6中,CombineTest是不推荐的:不推荐使用静态CombineTest

我们如何让它在RXJS 6中工作

在尝试CombineTest的RXJS6格式时

combineLatest(this.num3,this.num2, this.num1, (c1,c2) =>  Math.abs(c1 - c2 )),filter(x => x !== NaN);
我犯了一个错误

我通过gitter@Dorus和@GuillaumeUnice让它在帮助下工作

this.num3 = this.num1.pipe(combineLatest(this.num2),map(([n1,n2]) =>  Math.abs(n1 - n2))); 

观察:作为一名开发人员,仅仅一个简单的算术运算就这么复杂,这很奇怪

只有结果选择器不推荐使用,请参见直接使用CombineTest:CombineTestThis.num1,this.num2,c1,c2=>Math.absc1-c2;不过你不是在做简单的算术运算。随着时间的推移,您正在处理两个并行的数据流。有很多方法可以解释减去它们意味着什么。我忘了这些是小溪。这是有道理的。
this.num3 = this.num1.pipe(combineLatest(this.num2),map(([n1,n2]) =>  Math.abs(n1 - n2)));