rxjs里combineLatest operators的用法

时间:2022-07-28
本文章向大家介绍rxjs里combineLatest operators的用法,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

Whenever any input Observable emits a value, it computes a formula using the latest values from all the inputs, then emits the output of that formula.

这个图的一些解释:

看个例子:

const firstTimer = timer(0, 1000); // emit 0, 1, 2... after every second, starting from now
const secondTimer = timer(500, 1000); // emit 0, 1, 2... after every second, starting 0,5s from now
const combinedTimers = combineLatest(firstTimer, secondTimer);
combinedTimers.subscribe(value => console.log('diablo: '
 + value));

测试结果:

时间轴分析: