Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 - dynamic "for" attribute in ngFor [duplicate]

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

like image 504
Asaf Hananel Avatar asked Oct 25 '16 11:10

Asaf Hananel


1 Answers

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

like image 69
MatWaligora Avatar answered Sep 25 '22 01:09

MatWaligora