RxJs: how to get values emitted before we subscribe?

随声附和 提交于 2019-12-10 23:16:30

问题


With RxJs, once we start subscribe to an observable, we will start getting values once they are emitted, but how do I get all the values emitted by an observable before I've subscribed to it?


回答1:


An observable is just a function that returns 0 or more values between now and the end of time. Like any other function it doesn't do anything before it's called (subscribed to).

That being said, you can transform your observable to a hot observable by calling:

// This makes the observable 'connectable'
myObservable.publish();
// And make it start emitting items
myObservable.connect();

Alternatively, if you create the observable from say an array, you could ofcourse just look at the array :)



来源:https://stackoverflow.com/questions/41281879/rxjs-how-to-get-values-emitted-before-we-subscribe

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