Search code examples
angulardartangular-dart

How do i share data between sibling components in Angular dart


How to share data to sibling component in Angular dart

How to share data dynamically between sibling components Could you please explain with an example

thanks.


Solution

    • You can use a shared service that is provided by the parent component or another common ancestor, inject it in both components and use it as mediator, for example with streams to actively notify about state changes.

    • You can also use a field in the parent component that you pass to both

    <sibling1 [data]="dataInParent"></sibling1>
    <sibling2 [data]="dataInParent"></sibling1>
    
    • You can reference use references in the template of the parent component
    <sibling1 #foo1></sibling1>
    <sibling2 [data]="foo1.data"></sibling1>