RXJS 5 .subscribe() without arguments

99封情书 提交于 2019-12-05 02:42:37

.subscribe() actually doesn't require any parameters, it will just create an emptyObserver if none are given, which should work just as well.

It is possible though, that there are issues related to this in some of the 5.0.0-beta versions - in case you are using one of those versions, you should update to a more stable release.

const obs$ = Rx.Observable.of("Foo")
  .do(() => console.log("triggered!"));
  
obs$.subscribe();
obs$.subscribe();
<script src="https://unpkg.com/rxjs@5.1.1/bundles/Rx.min.js"></script>

Thanks to Damian Hercun for informing that this was a now-fixed bug in RxJS 5.4.2.

Info:

https://github.com/ReactiveX/rxjs/pull/1935

https://github.com/ReactiveX/rxjs/issues/1921

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!