简体   繁体   中英

Angular2: Adding components dynamically

I am planning to add dynamic components at certain location in my Angular 2 app. I tried adding anchor points but it didn't work.

Use an anchor Point in html

In ts file

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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