简体   繁体   English

在 Rxjs 中使用 mergeMap 时未定义 output

[英]undefined output while using mergeMap in Rxjs

Theoretically, I know what mergeMap is and how it works, but when I try to understand using practical approach I get confused, this is what I have done so far从理论上讲,我知道什么是 mergeMap 以及它是如何工作的,但是当我尝试使用实际方法来理解时,我会感到困惑,这就是我到目前为止所做的

const input1$= of("value 1","value 2","value 3");
const input2$= of(1,2,3,4);
const obs=input1$.pipe(
            mergeMap(data1=>{
              return input2$
              .pipe(map(ch=>{ch+' '+data1}))})
        )   

unfortunately, I am getting undefined when I try to merge them, your help would be appreciated to make me understand how it works.不幸的是,当我尝试合并它们时,我变得不确定,如果您能帮助我了解它是如何工作的,我们将不胜感激。

You are not returning anything in your second pipe您没有在第二个 pipe 中返回任何内容

Try this尝试这个

 const obs=input1$.pipe( mergeMap(data1=>{ return input2$.pipe(map(ch=>{ return ch+' '+data1 }))}) )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM