Angular 2 Child1-Parent-Child2事件传播 [英] Angular 2 Child1-Parent-Child2 event propagating

查看:84
本文介绍了Angular 2 Child1-Parent-Child2事件传播的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只在Angular 2上工作了几周,所以请尝试体贴一下,也许能给我一些有用的建议?谢谢你.我有一个主要组件(pageComponent),其模板内部还有另外两个较小的组件(tableComponent和filterComponent),每个组件都有自己的功能和属性.如何捕获在一个子组件中创建的事件并将其传播到同一父组件的另一个子组件?换句话说,如何在同一父组件模板的两个兄弟组件之间传播和通信事件?

I am working on Angular 2 for only couple of weeks, so try to be considerate, please, and maybe give me some useful advice? Thank you. I have a main component(pageComponent), that inside its template has other two smaller components(tableComponent and filterComponent), each with its own functions and properties. How do I catch an event created in one of the child components and propagate it to another child component of the same parent? In other words, how to propagate and communicate events between two sibling components within the same parent component's template?

推荐答案

您可以使用通量模式.基本上,您的组件可以订阅从您的服务中公开的事件.由于服务是单例的,因此无论它们在组件树中的深度如何,您都可以在组件之间共享它提供的数据.这是一个示例:

You can use the Flux pattern. Basically have your components subscribe to events exposed from your service. Since services are singletons, you can share the data that it provides across components, no matter how deep they are in the component tree. Here is an example: How can I maintain the state of dialog box with progress all over my Angular 2 application?

这篇关于Angular 2 Child1-Parent-Child2事件传播的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆