What is the difference between Promises and Observables?

后端 未结 30 2692
小鲜肉
小鲜肉 2020-11-21 23:48

What is the difference between Promise and Observable in Angular?

An example on each would be helpful in understanding both the cases. In w

30条回答
  •  走了就别回头了
    2020-11-22 00:32

    Promise

    A Promise handles a single event when an async operation completes or fails.

    Note: There are Promise libraries out there that support cancellation, but ES6 Promise doesn't so far.

    Observable

    An Observable is like a Stream (in many languages) and allows to pass zero or more events where the callback is called for each event.

提交回复
热议问题