Russian Federation
Russian Federation

Reputation: 194

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.

Upvotes: 2

Views: 382

Answers (1)

Bogdan Chereghi
Bogdan Chereghi

Reputation: 61

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
              }))})
        )

Upvotes: 2

Related Questions