根据此链接:https://medium.com/front-end-hacking/dynamically-add-components-to-the-dom-with-angular-71b0cb535286
我尝试将数据从Component注入其他人,然后尝试追加<dynamic-component [componentData]="data"></dynamic-component>
第一个组件
componentData = any;
//Calling API
if (success)
{
this.componentData = {
component: NewsFeedComponent,
inputs: {
new_data: this.result
},
};
}
第二个组件
constructor( private injector: Injector) {
this.data = this.injector.get('new_data');
}