How do observables differ from promises in angular?
Both observables and promises deal with asynchronous functionalities in Javascript however differ by one another-
Observables | Promises | |
---|---|---|
1. | Observables are lazy i.e. they won't be executed until we subscribe them by subscribe() method. | Are not lazy i.e. they executed just after creation. |
2. | They deal with multiple asynchronous events at a time. | Promises handle single asynchronous events at a time. |
3. | You can cancel the subscription using the unsubscribe() method. | They are not cancellable. |
4. | Observables deliver bugs to the subscribers. | It passes the errors to child promises. |
BY Best Interview Question ON 22 Sep 2021