Javascript 在两个解耦组件之间创建连接
我试图找到一种方法来创建一个组件和一个完全解耦的子组件之间的连接 例如,如果我有两个组件,Javascript 在两个解耦组件之间创建连接,javascript,angular,typescript,Javascript,Angular,Typescript,我试图找到一种方法来创建一个组件和一个完全解耦的子组件之间的连接 例如,如果我有两个组件,parent component和child component,它们只存在于标记中的parent component中,那么我需要找到一种方法让parent component和child component进行双向通信 例如,如果我有以下标记: <parent-component> <child-component></child-component>
parent component
和child component
,它们只存在于标记中的parent component
中,那么我需要找到一种方法让parent component
和child component
进行双向通信
例如,如果我有以下标记:
<parent-component>
<child-component></child-component>
<child-component></child-component>
<child-component></child-component>
<child-component></child-component>
<child-component></child-component>
</parent-component>
我需要父组件引用每个子组件的状态,每个子组件引用父组件的状态
在Angular 2中有没有办法做到这一点?我到处都找遍了,真的找不到解决办法。如果你想让父母和孩子彼此交流,Angular2建议你使用服务。这在食谱中有介绍:如果你想让父母和孩子彼此交流,Angular2建议使用服务。这在食谱中有介绍:听起来你需要一项服务。文档中也有介绍,我们试图避免使用服务,但如果这是唯一的方法,那就这样吧。添加一个答案,我会接受的。听起来你需要一个服务。文档中包含了这一点。我们试图避免使用服务,但如果这是唯一的方法,那就这样吧。添加一个答案,我将接受它。