1

I'm building a dynamic form following the cookbook documentation

In addition, I have a directive with the selector input[type=signature].

If I use this in dynamic-form-question.component.ts:

<input *ngSwitchCase="'signature'"
            [id]="question.attribs.name" 
            [formControlName]="question.attribs.name" 
            type="signature" 
            class="signature" />

my directive matches.

However, if I use

<input *ngSwitchDefault
            class="form-control"
            [formControlName]="question.attribs.name"
            [id]="question.attribs.name"
            [ngClass]="question.attribs.class"
            [placeholder]="question.attribs.placeholder"
            [type]="question.attribs.type" />

where the type.attribute is bound, it's no dice.

likewise I tried the selector input.signature and input.signature, input[type=signature], but they also don't work if the class or type attributes are bound.

Is this not supported, do I need to do something else to get this functionality?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Brad Kent
  • 4,982
  • 3
  • 22
  • 26

1 Answers1

1

Directive selectors have to be static element names, attributes, or classes. They need to be added statically do the components template. Everything added dynamically in any way is not considered by Angular2.

The only workaround I know is to create the components at runtime (with static element names, attributes or classes) for directives and pipes to be created with them - like explained in Equivalent of $compile in Angular 2

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