What is the difference between subscribe and the async pipe?
Model answer
With subscribe, you receive values in code and must store them and unsubscribe yourself when the component is destroyed (unless the stream completes). With the async pipe in the template, Angular subscribes, shows the latest value and unsubscribes automatically.
Prefer the async pipe or toSignal for data shown on screen. Use subscribe only for side effects, and then use takeUntilDestroyed to clean up.
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 an Observable, and how is it different from a Promise?
- 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?