Angular2: data binding with routing children

别说谁变了你拦得住时间么 提交于 2019-12-11 01:37:49

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/36158891/angular2-data-binding-with-routing-children

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!