Communication Between Multiple Components

In this lesson, we will look at how to use services to communicate between components by sharing data, actions, features, etc.

Services are used to provide data to different components by performing the common operation inside the service and then being able to pass it to any component that needs the data.

This ensures that the components only display the view and the services take care of fetching data and sharing it throughout the application.

You can define such tasks inside a service class. This class then provided to the components that inject this service using Angular’s dependency injection mechanism.

The separation of concerns is the main reason why Angular services came into existence. An Angular service is a stateless object and provides some very useful functions. These functions can be invoked using an Angular component.

Creating an injectable service

ng generate service <service-name>

Get hands-on with 1200+ tech skills courses.