Angular2: data binding with routing children

I have a simple setup. I use a routing component with several child components that load dynamically depending on the route. I would like some of these child components to have data binding with the routing parent.

I will add the @Output () property for the child, but how can I get the routing parent to listen for the events that this event emitter emits?

Usually in a template with a statically defined component, I will do something like this:

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

and the parentEvent method of the parent will handle the event.

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

thank

+2
angular angular2-template angular2-routing
Mar 22 '16 at 15:42
source share
1 answer

This is currently not supported. You can use the shared service to exchange data with dynamically inserted children. The service can use Observable to allow the child or parents to subscribe to the changes and receive an active notification.

+2
Mar 22 '16 at 15:45
source share



All Articles