How to share data between two component?

Issue

I’m using angular 4,im not able to communicate with component.I have sidenav component and I want to share values sidebar to main component.
Thanks.

Solution

sidenav.component.ts
passData:any

sidenav.component.html
//Call your main component & share passData property
<app-component [passData]="passData"></app-component>

main.component.ts
@ViewChild(passData) passData: SidenavComponent;

Answered By – Rahul Dapke

Answer Checked By – Terry (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.