Promises and Observables

I am a beginner in angular 2 . In HTTP methods we are using Subject(BehaviourSubject) in our project and I know that Subject is a special kind of Observables and there are some unique features in that.

According to my knowledge,

  • Promises and Observables are used to get data from the API
  • We have to subscribe both promises or observables to get latest values
  • I cant get these things,

  • what is mean by cancellable and non-cancellable here?
  • Promises return single values while Observables return multiple values?
  • Anyone please explain me these things to understand better. Thanks in advance


    Promises return single values while Observables return multiple values

  • Promises give you a promise that a value will be returned. Observables offer a streaming mechanism and may raise multiple events/return multiple values for a single subscription.
  • what is mean by cancellable and non-cancellable here?

  • The observable subscription can be (and should be) cancelled once no longer needed. It kind of makes sense if you think that they can return values "forever". Promises do not support cancellations (I think it was in the spec but finally was not implemented)
  • Hope this helps

    链接地址: http://www.djcxy.com/p/55476.html

    上一篇: AngularJS中的可观察性和承诺之间的区别。

    下一篇: 承诺和观察