在Angular 4中使用嵌套组件并为子级调用父级方法(反之亦然)的最佳方法是什么? [英] What is the best way to use nested components in Angular 4 and calling a method of a parent to child and vice versa?
问题描述
请帮助我解释在Angular 4
中使用嵌套组件的最佳方法,并为子级调用父级方法,反之亦然.请通过示例和实时编辑器进行说明.
Please help me to explain the best way to use nested components in Angular 4
and calling a method of a parent to child and vice versa. Please explain with an example and live editor.
先谢谢了.
我想使用angular 4(例如tabset ngx-bootstrap)来学习和设计自己的Tabset或其他组件,但需要提前进行更多设计.我是angular> 2的新手.
I want to learn and design my own tabset or other components using angular 4 like tabset ngx-bootstrap but more in advance. I am new to angular > 2.
这是场景:
- 公开一个组件中的几个api.
- 使用该api设置/注册/检索组件的数据/方法/设置.
我想学习使用不同的软件设计模式将组件构建为框架.
I want to learn to build a component as a framework using different design pattern of software.
因此,想从经验丰富的不同组件之间的通信中以正确的方式掌握深度知识.我正在关注官方文档: https://angular.io/guide/component-interaction
Hence, want to grab depth knowledge in correct way from experienced about communication between different components. I am following official documentation: https://angular.io/guide/component-interaction
推荐答案
我详细介绍了拉扎尔提到的第一种技术:在此处使用@Input和@Output: https://blogs.msmvps.com/deborahk/passing-data-to-and从嵌套组件中引发事件/
I have details on the first technique Lazar mentions: using @Input and @Output here: https://blogs.msmvps.com/deborahk/passing-data-to-and-raising-an-event-from-a-nested-component/
这篇关于在Angular 4中使用嵌套组件并为子级调用父级方法(反之亦然)的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!