Home > Net >  How to Skip the API call using RxJS skip operator?
How to Skip the API call using RxJS skip operator?

Time:12-15

I'm trying to skip the very first API call using the skip operator in RxJS . But I am not able to achieve that .

const source = of('a', 'b', 'c', 'd', 'e');

const example = source.pipe(
  tap(() => console.log('Service call triggered')), // I'm using a switchMap here to trigger the API call , tap is just for explaining the issue
  skip(1)
); 

const subscribe = example.subscribe((val) => console.log(val));

In the above example, I'm seeing 5 console.logs . But I want to see only 4 console.logs . Could you help, please?

Stackblitz

CodePudding user response:

Try below code:

const example = source.pipe(
  skip(1),
  tap(() => console.log('Service call triggered')), 
);

const subscribe = example.subscribe((val) => console.log(val));
  • Related