2016-06-07 87 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