使用ngFor和ngFormControl

时间:2016-07-09 11:39:54

标签: angular angular2-template angular2-forms

我正在尝试根据可能的复选框数组生成一个复选框

<div class="row" *ngFor="let category of Categories" >
      <input type="checkbox" name={{category}}
      [ngFormControl]="myForm.controls[{{category}}]"> {{category}}
  </div>

但是这不起作用,因为{{category}}的{​​{1}}似乎没有被适当的值替换。

我得到的错误是

  

得到插值({{}}),其中表达式位于第27列   [myForm.controls ['{{category}}']]费用@ 46:4(“ow”   * ngFor =“let category of Categories”&gt;       ] [ngFormControl] = “myForm.controls [ '{{类别}}']” &GT; {{类别}}

1 个答案:

答案 0 :(得分:1)

只是一个错字,替换:

*ngFor="let category of Cateories"

由:

*ngFor="let category of Categories"