2
当我们希望父组件监听孩子的事件,我们使用 @output参数和订阅父标记:输出参数
<my-tag (onMyEvent)="onMyEvent($event)"></my-tag>
我怎么用ComponentResolver办呢?
当我们希望父组件监听孩子的事件,我们使用 @output参数和订阅父标记:输出参数
<my-tag (onMyEvent)="onMyEvent($event)"></my-tag>
我怎么用ComponentResolver办呢?
这不被支持。
- 使用与使用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;
});
再次感谢。我使用这个解决方案:父母和孩子通过服务进行交流https://angular.io/docs/ts/latest/cookbook/component-communication.html#!#bidirectional-service – Avi