TommyF
TommyF

Reputation: 7150

Applying directives during dynamic component initialization

I'm using the ComponentFactoryResolver to dynamically create components.

const factory = this.componentFactoryResolver.resolveComponentFactory(FooComponent);
const component = this.templateRoot.createComponent(factory).instance;

Is it possible to conditionally apply directives here?

Upvotes: 0

Views: 230

Answers (1)

Günter Zöchbauer
Günter Zöchbauer

Reputation: 657721

The only supported way to apply directives is to add markup to a components template statically.

You can compile a component dynamically if you need to do that at runtime.

See for example How can I use/create dynamic template to compile dynamic Component with Angular 2.0?

Upvotes: 1

Related Questions