Reputation: 492
I'm curious about the reasoning or discussion that lead to the angular 2 http
service returning an observable instead of a promise for the response. I would understand the logic for something like a web socket connection or long-polling request, but the http
service simply creates an XMLHttpRequest
, and in the load
event handler for the request, emits the response on the response observable and then completes the observable. Since this only returns one value, it seems to me like a promise would make more sense.
Edit: I am aware of the difference between observables and promises, and know that you can convert observables to promises and vice versa. My question is more about the reasoning behind the decision to return an observable instead of a promise.
Upvotes: 11
Views: 2021
Reputation: 657721
I think the main reason was that observables can be cancelled.
See also Angular - Promise vs Observable.
Upvotes: 5