【发布时间】:2022-01-17 13:18:24
【问题描述】:
我正在尝试使用 RxJS 中的 skip 运算符跳过第一个 API 调用。但我无法做到这一点。
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));
在上面的示例中,我看到 5 console.logs 。但我只想看到 4 个 console.logs 。请问您能帮忙吗?
【问题讨论】:
-
skip需要之前tap才能真正跳过第一个控制台日志。 -
操作员顺序在这里很重要。尝试将
skip(1)移到顶部,它应该可以工作,就像提到的@AT82 一样 -
在 stackblitz 中我只看到来自订阅的 4 个控制台日志
-
@ShamPooSham 很好,似乎顺序是正确的,
skip在tap之前 :)
标签: javascript angular typescript rxjs rxjs6