Component communication using services
In this recipe, you’ll start with an app with a parent component and a child component. You’ll then use an Angular service to establish communication between them. We’re going to use BehaviorSubject and Observable streams to communicate between components and the service.
Getting ready
The project for this recipe resides in start/apps/chapter01/cc-services:
- Open the project in Visual Studio Code.
- Open the terminal, navigate to the code repository directory, and run the following command to serve the project:
npm run serve cc-servicesThis should open the app in a new browser tab, and you should see the app as follows:

Figure 1.4: The cc-services app running on http://localhost:4200
How to do it…
Similar to the previous recipe, we have an app with AppComponent, NotificationsButtonComponent, and NotificationsManagerComponent. AppComponent is the parent...