简体   繁体   English

从 angular 中的兄弟组件的子组件调用父组件 function

[英]calling parent component function from child of siblings component in angular

I have 2 component(comp1 and comp2) in main component that component2 has child component, I have tried to call a function in a component1 from child component of component2.我在组件2有子组件的主组件中有2个组件(comp1和comp2),我试图从component2的子组件调用component1中的function。

You can read this usefull article about sharing data between Angular Components.您可以阅读这篇关于在 Angular 组件之间共享数据的有用文章。

You can share Data via ViewChild or Output() and EventEmitter from child to parent(comp2 child to comp2) and then share these data to the sibling comp 1. But i think the best way is to use a service where you can share data on unrelated Components您可以通过 ViewChild 或 Output() 和 EventEmitter 从子节点到父节点(comp2 子节点到 comp2)共享数据,然后将这些数据共享给兄弟 comp 1。但我认为最好的方法是使用可以共享数据的服务不相关的组件

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

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