简体   繁体   English

如何将数据从子组件传递给父组件 [Angular]

[英]How to pass data from child component to parent [Angular]

I'm learning Angular.我正在学习 Angular。 I want to see how a Child component Output data to Parent component.我想看看子组件如何将数据Output到父组件。 I've gone through some articles and documentation then created a minimal program.我浏览了一些文章和文档,然后创建了一个最小程序。 I'm able to send data from Parent to Child successfully but not the vice-versa.我能够成功地将数据从父级发送到子级,但反之亦然。 I'm not getting any error but I'm not getting the values also.我没有收到任何错误,但我也没有得到值。 Can you please see my code and correct me.你能看看我的代码并纠正我吗? Here is my stackblitz .这是我的堆栈闪电战

It is working, you just don't show the value of ChildCurrentVal anywhere.它正在工作,您只是不要在任何地方显示 ChildCurrentVal 的值。

Put

{{ChildCurrentVal}}

In the template somewhere在模板中的某处

working demo : demo工作演示:演示

You have missed to place {{ChildCurrentVal}} in app.component.html and not only that your child component will return value only when your child receive value from parent otherwise it return undefined .您错过了在app.component.html放置{{ChildCurrentVal}}并且不仅您的子组件仅在您的子组件从父组件接收到值时才会返回值,否则返回undefined

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM