This is a more general question, so I'm also giving general information. In Angular I'm using a parent component, which contains 2 child components. These 2 child components needs to share information with each other:
<parent-component>
<child1-component></child1-component>
<child2-component></child2-component>
</app-parent>
So, child1 needs information from child2 and child2 needs information from child1 (and its different information). The reason that child1 and child2 are not in one component (because that would solve the problem of course) is that it would be a very big component and I want to use child1 at another page without child2.
So I already found 2 solutions:
1: Handle all outputs of the childs in the parent and provide inputs for them as well. This means that for every output that a child has (either child1 or child2), the parent must implement a handler for it, specify a variable and bind that to an input of the other child.
2: Use a service that is injected in both childs. A child calls a method of the service, it triggers and event which will be handled by the other child directly.
Now what in your opinion is the best approach? Or is there a third and even better approach?
Thanks in advance, Herman