There are some best practices to follow when dealing with data services in Angular, especially when Observables are involved, and those are:
- Handle your errors. This one goes without saying and hopefully this is not something new on your radar.
- Make sure that any manually created Observables have a cleanup method.
- Unsubscribe to your streams/Observables, or else you might have resource leaks.
- Use the async pipe to manage the subscribe/unsubscribe process for you.
We have so far not discussed how to create a cleanup method when manually creating Observables, which is why we will cover that in a subsection.
The async pipe has been mentioned a couple of times in the Firebase section, but it's worth mentioning again and building on that knowledge by explaining its role in the subscribe/unsubscribe process to streams.