What is the difference between Promises and Observables?

后端 未结 30 3095
小鲜肉
小鲜肉 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:36

    In a nutshell, the main differences between a Promise and an Observable are as follows:

    • a Promise is eager, whereas an Observable is lazy,
    • a Promise is always asynchronous, while an Observable can be either synchronous or asynchronous,
    • a Promise can provide a single value, whereas an Observable is a stream of values (from 0 to multiple values),
    • you can apply RxJS operators to an Observable to get a new tailored stream.

    a more detailed can be found in this article

提交回复
热议问题