2016-06-07 69 views
2

当我们希望父组件监听孩子的事件,我们使用 @output参数和订阅父标记:输出参数

<my-tag (onMyEvent)="onMyEvent($event)"></my-tag> 

我怎么用ComponentResolver办呢?

回答

6

这不被支持。
- 使用与使用ViewContainerRef.createComponent()
动态添加的组件共享的服务 - 使用componentRef它必须返回导线输入和输出。

this.resolver.resolveComponent(this.type).then((factory:ComponentFactory<any>) => { 
    this.cmpRef = this.target.createComponent(factory); 
    this.cmpRef.instance.someOutput.subscribe(...) 
    this.cmpRef.instance.someInput = this.someInputValue; 
}); 
+1

再次感谢。我使用这个解决方案:父母和孩子通过服务进行交流https://angular.io/docs/ts/latest/cookbook/component-communication.html#!#bidirectional-service – Avi