Angular 2 - 输入类型复选框未被检查

时间:2018-06-15 08:05:04

标签: angular checkbox

我在控制台中获取值检查但未显示复选框。

下面给出了代码和控制台

  <input type = "checkbox" (click)="selectCutype('single',cutType.id)"  id="cutType{{cutType.attribute_value}}"  (change)="changeCheckbox(i)" >
        {{cutType.attribute_value}}


 this.array = self.fifthSector.attribute_value_id.split(',');

 console.log('array',this.array)this.array.forEach((elem1, index) => {elem1;
       console.log(elem1)
      res[0].cut_type_sub.forEach((elem2, index) => {elem2;
        console.log(elem2.id)
         if(elem1 == elem2.id)
         {
          //--If elem1 equal elem2
          this.fish_cuttype[index].checked = !this.fish_cuttype[index].checked;
           console.log('Done',elem1 == elem2.id,this.fish_cuttype[index])
         }
       });

enter image description here

1 个答案:

答案 0 :(得分:2)

[(ngModel)]checked属性

一起使用
  <input type = "checkbox" [(ngModel)]="cutType.checked" (click)="selectCutype('single',cutType.id)"  id="cutType{{cutType.attribute_value}}"  (change)="changeCheckbox(i)" >