Reputation: 1842
Can anyone explain to me Observables? They keep referring to observables as like promises. If I can call a method and return data, why do I need an observable?
Upvotes: 0
Views: 52
Reputation: 5425
Promises sugar coat the callback pattern, do this then that then other
. A Promise will act on data and either return a value or an error.
Since the creation of JavaScript, event listeners have been listening to and reacting to events in the browser. Observables are the latest and greatest abstraction of the observer pattern. It doesn't matter what the data source is, you can wrap an Observable around it.
When you are dealing with a stream of data, a Promise isn't of any use to you because the stream may not end, Observables solve the problem. Angular 2 uses Observables instead of Promises for dealing with HTTP.
Upvotes: 1
Reputation: 288
Angular is non blocking having promises/Observables allows your code to continue to run while the data you have requested is retrieved.
Upvotes: 1