What is an Observable, and how is it different from a Promise?
Model answer
An Observable is a stream of values over time that you subscribe to. A Promise gives one value, once, and starts immediately. An Observable can emit many values, is lazy (nothing happens until you subscribe), can be cancelled by unsubscribing, and has many operators to transform streams.
HTTP calls in Angular return Observables that emit one value and complete, which is why they are easy to use with the async pipe.
Learn this topic
Angular Tutorial: Beginner to Advanced .
Sign in to add your own answer.
More questions
- How do you call an API in Angular?
- What is the difference between subscribe and the async pipe?
- What are common RxJS operators you use, and what do they do?
- Explain the difference between switchMap, mergeMap, concatMap and exhaustMap.
- What are HTTP interceptors, and what are they used for?
- How do you handle errors from HTTP calls?