What is the difference between a Observable and a Subject in rxjs?

前端 未结 8 1028
难免孤独
难免孤独 2020-12-01 00:05

i was going through this blog and to read about Observables and i couldnt figure out the difference between the Observable and a Subject

8条回答
  •  [愿得一人]
    2020-12-01 00:49

    From another perspective, it is good to note that the subscription to an Observable re-execute the Observable function. This can lead performance issue if the data source is a service for instance.

    If you want several subscribers to get the same value, you may need a Subject. For this, make sure that your subscription is set before the Subject subscribed to the data source. Otherwise, your process would be stuck.

    More details here: https://javascript.tutorialhorizon.com/2017/03/23/rxjs-subject-vs-observable/

提交回复
热议问题