简体   繁体   English

Angular2:动态添加组件

[英]Angular2: Adding components dynamically

I am planning to add dynamic components at certain location in my Angular 2 app. 我计划在Angular 2应用程序中的某些位置添加动态组件。 I tried adding anchor points but it didn't work. 我尝试添加锚点,但是没有用。

Use an anchor Point in html 在HTML中使用锚点

In ts file 在ts文件中

constructor(private componentFactoryResolver: ComponentFactoryResolver,
    private viewContainerRef: ViewContainerRef) {}

Create a component factory Get the reference of the anchor point Bind any data if required Run detect changes for updating it 创建组件工厂获取锚点的参考如果需要,请绑定任何数据运行检测更改以进行更新

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM