2016-08-22 26 views
1

我想知道是否有任何方式从Angular2中的动态加载组件传回数据。我通过使用从动态加载的组件传回数据返回到父页面Angular2

this._dcl.loadIntoLocation(...).then(component => { 
    component.instance.variable = this.variable; 
} 

在完成任务的组件内,在我的情况下,模态组件数据,我可以以类似的方式传递数据或变量回来了?提前致谢。

回答

2

您可以将Observable添加到动态添加的成分
(一个EventEmitter可能工作很好,但可能最终破裂,然后Angular2队并不能保证一个EventEmitter将继续表现得像一个可观察)

然后刚刚订阅此观察的

this._dcl.loadIntoLocation(...).then(component => { 
    component.instance.variable = this.variable; 
    component.instance.someObservable.subscribe(val => this.someVal = val); 
} 

DynamicComponentLoader已被弃用,据我所知在主已经删除。

另请参见Angular 2 dynamic tabs with user-click chosen components

+0

非常感谢的人,尤其是阅读材料 – ConorJohn