【问题标题】:undefined output while using mergeMap in Rxjs在 Rxjs 中使用 mergeMap 时未定义的输出
【发布时间】:2020-12-08 23:34:52
【问题描述】:

理论上,我知道什么是 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}))})
        )   

不幸的是,当我尝试合并它们时,我变得不确定,如果你能帮助我了解它是如何工作的,我们将不胜感激。

【问题讨论】:

  • 您的管道中没有退货return ch+' '+data1
  • 你能告诉我怎么做吗?

标签: angular rxjs rxjs5 rxjs6 rxjs-pipeable-operators


【解决方案1】:

您没有在第二个管道中返回任何内容

试试这个

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

【讨论】:

  • 谢谢@Bogdan Chereghi,我给了你+1并接受了作为答案
  • @RussianFederation 谢谢
猜你喜欢
  • 2020-02-05
  • 2022-01-24
  • 1970-01-01
  • 2021-12-12
  • 1970-01-01
  • 2021-07-18
  • 2020-03-28
  • 2018-12-07
相关资源
最近更新 更多