Search code examples
angularrxjsrxjs5rxjs6rxjs-pipeable-operators

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

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.


Solution

  • You are not returning anything in your second pipe

    Try this

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