任何需要先取消订阅 RxJS() [英] Any need to call unsubscribe for RxJS first()
本文介绍了任何需要先取消订阅 RxJS()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在以下代码中:-
RxJS.Observable.of(1,2).first().subscribe((x) => console.log(x););
给定操作符first()
是否有必要取消订阅?
is it necessary to unsubscribe given the operator first()
?
推荐答案
没有.它在调用 first()
后自动取消订阅.当前的语法是 observable.pipe(first()).subscribe(func);
对于 RxJS 6.
No. It unsubscribes automatically after calling first()
. The current syntax is observable.pipe(first()).subscribe(func);
for RxJS 6.
文档 指出:
如果不带参数调用,first
发出源 Observable 的第一个值,然后完成.
If called with no arguments,
first
emits the first value of the source Observable, then completes.
这篇关于任何需要先取消订阅 RxJS()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文