Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

send data between two component whose parent component is same

enter image description here

  • I have two child component product-list.component, product-details.component whose parent component is products.component.

    • In product-list.component , I am displaying list of dummy products.
    • In product-details.component, I want to display clicked product details. After clicking the list, I am getting selected product in parent component(products.component) .

*I want to display the selected product in product-details.component.

Link of project is here

like image 551
yash Avatar asked Feb 27 '19 12:02

yash


People also ask

How do you transfer data from one component to another?

For passing the data from the child component to the parent component, we have to create a callback function in the parent component and then pass the callback function to the child component as a prop. This callback function will retrieve the data from the child component.

How to pass data from one component to another using EventEmitter?

Child to parent component If you want to pass data from the child component to the parent component use @Output() and EventEmitter. To pass data from the child to the parent, you have to emit it from the child.


1 Answers

You were almost there. The output of the ProductListComponent becomes the input of the ProductDetailsComponent. For that, you just have to set the input of your ProductDetailsComponent in your products.component.html:

<app-product-details [detailRowInput]="detailSingleRow"></app-product-details>

see stackblitz

like image 124
Kim Kern Avatar answered Sep 25 '22 14:09

Kim Kern