7

When i write dynamic "for" attribute in label, i get error.

example:

<div *ngFor="let question of questions; let i = index;">
        <input id="ques-{{i}}" type="radio" name="selected" [value]="question">
        <label for="ques-{{i}}">{{question.data}}</label>
</div>

the error :

Unhandled Promise rejection: Template parse errors: Can't bind to 'for' since it isn't a known property of 'label'.

the dynamic "id" attribute working fine, please help me to find a solution

Asaf Hananel
  • 7,092
  • 4
  • 24
  • 24

1 Answers1

20

You have to access label's attribute like this: [attr.for]="'ques-' + i"

Smi
  • 13,850
  • 9
  • 56
  • 64
MatWaligora
  • 1,207
  • 1
  • 12
  • 15
  • 1
    Hi thanks it is working!,But why dont i have access to the 'for' attribute? why do i have to use the [attr]? – Asaf Hananel Oct 25 '16 at 11:48
  • 3
    Because there are a few attributes like 'for' 'data' 'aria' and probably a few more that don't have "angular" bindings and you can't use string interpolation within them – MatWaligora Oct 25 '16 at 11:49