What is the difference between Promises and Observables?

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

    Promises and Observables both handle the asynchronous call only.

    Here are the differences between them:

    Observable

    1. Emits multiple values over a period of time
    2. Is not called until we subscribe to the Observable
    3. Can be canceled by using the unsubscribe() method
    4. Provides the map, forEach, filter, reduce, retry, and retryWhen operators

    Promise

    1. Emits only a single value at a time

    2. Calls the services without .then and .catch

    3. Cannot be canceled

    4. Does not provide any operators

提交回复
热议问题