Creation and subscription
Observables in Angular are created using the Observable
class, and we can subscribe to them using the subscribe
method. This allows us to receive emitted values over time, unlike Promises, which resolve once and cannot emit multiple values.
Cancellation and error handling
Observables can be canceled by unsubscribing, stopping further emissions, and avoiding memory leaks. They also offer robust error handling, enabling retries or fallback strategies, unlike Promises, which either resolve or reject and cannot be canceled.
Chaining
Observables can differentiate between transformation and subscription. Promises don’t have this ability and cannot perform multiple operations on values. Observables can transform the values using multiplication, addition, filtration, concatenation, and several other methods. Here is an example of how it can be done.