What is the difference between Promises and Observables?

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

    • Provide a single future value;
    • Not lazy;
    • Not cancellable;

    Observable:

    • Emits multiple values over time;
    • Lazy;
    • Cancellable;
    • Supports map, filter, reduce and similar operators

    You can use promises instead of observables when calling HTTP in Angular if you wish.

提交回复
热议问题