What is the difference between Promises and Observables?

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

    Short answer :

    Observable is better, it has all Promises features plus extra features.


    Long answer:

    Promises:

    • One Time Use "Return data once"
    • No cancel
    • One listener
    • No Socket Support One Listener

    Observable:

    • Return Data many times as data change
    • Support cancel
    • Support socket
    • Support many Listener and notify them when data change
    • Support map, filter, reduce

提交回复
热议问题