0

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?

Valeriy
  • 1,365
  • 3
  • 18
  • 45
TommyF
  • 6,660
  • 8
  • 37
  • 61

1 Answers1

1

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?

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567