Angular 2 - Passing data to Child component after Parent initialisation

后端 未结 5 2029
花落未央
花落未央 2020-12-23 16:58

I have a parent component which is getting data from a server through a service. I need some of this data to be passed to the Child component.

I\'ve been trying to p

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-23 17:25

    I'm assuming that the child is getting a subset of the parents data, potentially from a user action (like loading a form when a user clicks on a grid row). In this case I would use an event.

    Have the parent fire an event, maybe dataSelected, and the contents of the event would be the data that was selected.

    Then have the child listen for those events and when fired load the data from the event into the model.

    This will help decouple your components, which always a good idea.

提交回复
热议问题