Angular2:动态添加组件

Angular2:动态添加组件,angular,Angular,我计划在Angular 2应用程序的特定位置添加动态组件。我尝试添加锚定点,但没有成功。在html中使用锚定点 在ts文件中 constructor(private componentFactoryResolver: ComponentFactoryResolver, private viewContainerRef: ViewContainerRef) {} 创建一个组件工厂 获取锚点的参考 如果需要,请绑定任何数据 运行检测更改以进行更新

我计划在Angular 2应用程序的特定位置添加动态组件。我尝试添加锚定点,但没有成功。

在html中使用锚定点

在ts文件中

constructor(private componentFactoryResolver: ComponentFactoryResolver,
    private viewContainerRef: ViewContainerRef) {}
创建一个组件工厂 获取锚点的参考 如果需要,请绑定任何数据 运行检测更改以进行更新