Observables in a Nutshell

Learn about observables in Angular and how they facilitate asynchronous event handling by emitting events over time.

An observable is an object that maintains a list of dependents, called observers, and informs them about state and data changes by emitting events asynchronously. To do so, the observable implements all the machinery it needs to produce and emit such events. It can be fired and canceled at any time, regardless of whether it has emitted the expected data already.

Observers need to subscribe to an observable to be notified and react to reflect the state change. This pattern, known as the observer pattern, allows concurrent operations and more advanced logic. These observers, also known as subscribers, keep listening to whatever happens in the observable until it is destroyed. We can see all this with more transparency in an actual example.

Enhancing asynchronous behavior with observables

  1. Replace setTimeout with setInterval in the onComplete method that was covered previously:

Get hands-on with 1400+ tech skills courses.