Angular 2 Sibling Component Communication

前端 未结 12 1291
深忆病人
深忆病人 2020-11-22 06:31

I have a ListComponent. When an item is clicked in ListComponent, the details of that item should be shown in DetailComponent. Both are on the screen at the same time, so

12条回答
  •  长情又很酷
    2020-11-22 07:08

    I have been passing down setter methods from the parent to one of its children through a binding, calling that method with the data from the child component, meaning that the parent component is updated and can then update its second child component with the new data. It does require binding 'this' or using an arrow function though.

    This has the benefit that the children aren't so coupled to each other as they don't need a specific shared service.

    I am not entirely sure that this is best practice, would be interesting to hear others views on this.

提交回复
热议问题