Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.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-用于.withLatestFrom的多个源_Angular_Rxjs_Ngrx - Fatal编程技术网

Angular RxJS-用于.withLatestFrom的多个源

Angular RxJS-用于.withLatestFrom的多个源,angular,rxjs,ngrx,Angular,Rxjs,Ngrx,我想合并来自多个观测值的最新发射值,所以现在我正在使用。withLatestFrom。除此之外,它将数据嵌套在嵌套数组中,而不是将数据推入新的数组值中。下面是示例代码 关于如何使用.withLatestFrom检索多个可观测发射,有什么想法吗 source0 .withLatestFrom(源1) .withLatestFrom(源2) .withLatestFrom(来源3) .map((数据)=>{console.log(数据)}); withLatestFrom支持多个观测值: .with

我想合并来自多个观测值的最新发射值,所以现在我正在使用
。withLatestFrom
。除此之外,它将数据嵌套在嵌套数组中,而不是将数据推入新的数组值中。下面是示例代码

关于如何使用
.withLatestFrom
检索多个可观测发射,有什么想法吗

source0
.withLatestFrom(源1)
.withLatestFrom(源2)
.withLatestFrom(来源3)
.map((数据)=>{console.log(数据)});

withLatestFrom
支持多个观测值:

.withLatestFrom(source1, source2, source3)
.map((data) => { console.log(data) });

-> [val, value1, value2, value3]
它还支持函数作为最后一个参数,因此您可以获取数组以外的值:

observable$
    .withLatestFrom(source1, source2, (val, one, two) => {
        return {val: val, one: one, two: two};
     });

withLatestFrom接受多个观测值。所以你可以这样写:

let obs1$ = Rx.Observable.of('a');
let obs2$ = Rx.Observable.of('b');

Rx.Observable.interval(1000)
  .withLatestFrom(obs1$, obs2$)
  .subscribe(x=>console.log(x))

您可以用
包装
{}
,这样就不需要显式的返回语句:
.withLatestFrom(source1,source2,(val,one,two)=>({val:val,one:one,two:two})