Angular 如何将动态组件插入运行时创建的容器中?

Angular 如何将动态组件插入运行时创建的容器中?,angular,Angular,动态加载角度组件是可以的,但我面临的问题是,我试图插入这个动态组件的容器也是在运行时构建的 显示您在解决问题上的努力。@SteveFest:在堆栈溢出本身上找到它:1)在构造函数中创建了ApplicationRef的实例2)然后nomal:let factory=this.componentFactoryResolver.resolveComponentFactory(arbitaryComponent);3) const ref=factory.create(this.injector,[],

动态加载角度组件是可以的,但我面临的问题是,我试图插入这个动态组件的容器也是在运行时构建的

显示您在解决问题上的努力。@SteveFest:在堆栈溢出本身上找到它:1)在构造函数中创建了ApplicationRef的实例2)然后nomal:let factory=this.componentFactoryResolver.resolveComponentFactory(arbitaryComponent);3) const ref=factory.create(this.injector,[],val);//在这里,val将引用动态HTML节点,在我的例子中,我通过getElementById属性//4)ref.instance.data=data获取它//将数据传入arbitaryComponent//5)this.app.attachView(ref.hostView)//完成//