[英]Get the data from Child Component to Parent Component
I have a question regarding the rendering of dynamic component. 我对动态组件的渲染有疑问。 I have a
Parent component
and a Child component
. 我有一个
Parent component
和一个Child component
。 In child component template
there are text fields and the user can enter values. 在
child component template
,有文本字段,用户可以输入值。 In there, I also have a submit button, the function of submit button is declared in the Parent Component
. 在那里,我还有一个提交按钮,在
Parent Component
声明了提交按钮的功能。
My problem now is when I clicked the submit button, I can't get the values that the user entered in Child Component Template
. 现在的问题是,当我单击“提交”按钮时,无法获得用户在“
Child Component Template
输入的值。 I have to get the latest data from child
to parent
. 我一定要得到的最新数据,从
child
到parent
。 I really don't have an idea on how to solve this I've seen @output
but still reading tutorial about it. 我真的不知道如何解决这个问题,我已经看过
@output
但仍在阅读有关它的教程。 Do you have any idea on how to achieve this? 您对如何实现这一目标有任何想法吗?
Basically the child component will output/emit an event with the data and parent component will subscribe/listen to the event (basically a Pub/Sub model). 基本上,子组件将输出/发出带有数据的事件,而父组件将订阅/监听事件(基本上是发布/订阅模型)。 This can be achieved through
EventEmitter
in Angular2. 这可以通过
EventEmitter
中的EventEmitter实现。 Please refer to this link also this one . 请参阅此链接也是这一个 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.