Unrelated components - sravanthimendu98/angular GitHub Wiki

Unrelated Components: Sharing Data via a Service

A shared service acts as a central point for data manipulation and communication between components. Components can share data by injecting and accessing the service.

In the service, we create a list object , and we are returning in getToDo function and we can accessing this service file in any of the component by adding in constructor constructor(public commonData: CommonService) { }

The parent, child, and sibling components all receive the same treatment. We inject the DataService in the constructor, then subscribe to the currentMessage observable and set its value equal to the message variable.

image

image