Sep 4, 2018 · 1 min read
Also, usage of Observable should be done if you are working on subscription of data. If you are hitting service only once to get REST data then there is no sense to have Observable subscription.
Actually there are quite a few reasons to use observables instead of promises even for single response endpoints:
- Consistency
- Easier map-reduce actions
- The ability to cancel in-flight requests with
subscription.unsubscribe(),switchMap, etc.
The classical example being an autocomplete control. The user keeps pressing keys and we send multiple requests to an endpoint. However, we are only ever interested in the response of the request that was sent last. switchMap handles this nicely for us.
