2

I have a simple setup. I'm using a routing component with multiple child components which are loaded dynamically depending on the route. I'd like for some of these child components to have data-binding with its routing parent.

I'll add an @Output() property to the child, but how can I make the routing parent listen for the events that this event-emitter emits?

Normally in a template with a statically defined component I'll do something like this:

<child (myevent)="handleEvent($event)">

and the parent's handleEvent method will handle the event.

But since routing insert the components dynamically, this is not possible. Is there a way to make it work? I know I can use a service to achieve the same result, but I'd like to avoid that in this case.

Thanks

laagland
  • 81
  • 6
  • Possible duplicate of [How do i share data between components in Angular2?](http://stackoverflow.com/questions/31026886/how-do-i-share-data-between-components-in-angular2) – Günter Zöchbauer Mar 22 '16 at 15:46

1 Answers1

2

This is currently not supported. You can use a shared service to share data with dynamically inserted children. The service can use Observable to allow child or parent to subscribe to changes and get actively notified.

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567