Components 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 chapter01/start_here/cc-services
:
- Open the project in Visual Studio Code.
- Open the terminal and run
npm install
to install the dependencies of the project. - Once done, run
ng serve -o
.This should open the app in a new browser tab and you should see the app as follows:
How to do it…
Similar to the previous recipe, we have an app with AppComponent
, NotificationsButtonComponent
, and NotificationsManagerComponent
. AppComponent
is the parent of the other two components mentioned...