Angular 2 - *ngFor带复选框和相应的标签

Ale*_*ski 7 angular

我在Angular 2中处理数据表.

<table-component>是一个常规的<table>内部我正试图<tr>使用Angular的*ngFor 来增加s,就像这样:

<tr *ngFor="#person of persons; #i = index">
Run Code Online (Sandbox Code Playgroud)

每个<tr>都有几个领域,一个checkbox有一个label.

我设置了checkbox类似的id属性:

<input type="checkbox" id="checkbox{{i}}">
<label for="checkbox{{i}}">{{person.finished}}</label>
Run Code Online (Sandbox Code Playgroud)

其中{{i}}是ngFor的局部变量.它工作正常,但仅适用于复选框.

当我尝试为atrribute"for"做同样的事情时,label我只会得到错误.

Unhandled Promise rejection: Template parse errors:
Can't bind to 'for' since it isn't a known native property ("
   <div>
        <input type="checkbox" id="checkbox{{i}}">
        <label [ERROR ->]for="checkbox{{i}}">{{person.finished}}</label>
    </div>
</td>
Run Code Online (Sandbox Code Playgroud)

我的问题是:

如何使用Angular 2的ngFor设置标签的"for"属性,因此它们指向右侧的复选框?

Thi*_*ier 14

您应该使用以下内容来设置attribut值:

<label [attr.for]="'checkbox'+i">{{person.finished}}</label>
Run Code Online (Sandbox Code Playgroud)