Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在两个解耦组件之间创建连接_Javascript_Angular_Typescript - Fatal编程技术网

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建议使用服务。这在食谱中有介绍:

听起来你需要一项服务。文档中也有介绍,我们试图避免使用服务,但如果这是唯一的方法,那就这样吧。添加一个答案,我会接受的。听起来你需要一个服务。文档中包含了这一点。我们试图避免使用服务,但如果这是唯一的方法,那就这样吧。添加一个答案,我将接受它。