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,268
  • 2
  • 17
  • 44
TommyF
  • 5,796
  • 5
  • 32
  • 56

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
  • 558,509
  • 191
  • 1,911
  • 1,506