The reactive pattern for sharing data

Angular services are powerful and efficient for creating common references for sharing both data and business logic between components. We’ll combine Angular services with observables, more specifically BehaviorSubject, to create stateful, reactive services that will allow us to synchronize the state efficiently across an entire application. So, in the following subsections, we’ll explain the steps to implement a reactive pattern to share data between unrelated or sibling components.

Creating a shared service

We’ll create an Angular service called SharedDataService using the Angular CLI, as usual, under the src/app/core/services folder.

Get hands-on with 1200+ tech skills courses.