phani1382
phani1382

Reputation: 42

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.

Upvotes: 2

Views: 671

Answers (1)

indra257
indra257

Reputation: 86

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

Upvotes: 3

Related Questions