【发布时间】:2016-04-05 20:35:29
【问题描述】:
我使用了 Angular2 动态组件加载器。一切正常。
我的动态加载的组件发出事件,但我无法在任何地方捕获它。
父代码:
this.dcl.loadAsRoot(SomeComponent, "#dynamiccomponenthere", this.injector)
父模板:
<div id="dynamiccomponenthere" (somecustomevent)="someFunc()"></div>
孩子:
...
this.somecustomevent.emit(data)
...
*解决方案:(感谢 Gunther)*
cmp.instance['somecustomevent'].subscribe(ev => {
this.consoleLog(ev) // run function in parent!
})
【问题讨论】:
标签: typescript angular