温馨提示:本文翻译自stackoverflow.com,查看原文请点击:typescript - Why all checkbox of column getting checked when checking single checkbox
angular typescript

typescript - 为什么在检查单个复选框时选中了该列的所有复选框

发布于 2020-03-28 23:21:51

我在桌子上工作。表格的一列具有复选框。当我单击一个复选框时,该列的所有复选框都会被选中。

这是我的代码

<td>                   
<label class="container"> 
  <input type="checkbox" [(ngModel)]="theCheckbox"  data-md-icheck (change)="toggleVisibility($event)"/>
      Checkbox is <span *ngIf="marked">checked</span><span *ngIf="!marked">unchecked</span>
  </label>
</td>

toggleVisibility函数为空

toggleVisibility(data)
{
}

我该如何解决这个问题?

查看更多

查看更多

提问者
Arvind Chourasiya
被浏览
14
BartoszTermena 2020-01-31 17:46

尝试这样的事情:

<table >
  <thead>
    <tr>
      <th *ngFor="let head of headElements" scope="col">{{head}} </th>
    </tr>
  </thead>
  <tbody>
    <tr  *ngFor="let el of elements;let index = index;">
      <th scope="row">{{el.id}}</th>
      <td>{{el.first}}</td>
      <td>{{el.last}}</td>
      <td>                   

    <input type="checkbox" [(ngModel)]="el.checked" >
    <span *ngIf="el.checked" >checked</span>
    </td>
    </tr>
  </tbody>
</table>

https://stackblitz.com/edit/angular-mnrmpp?file=src/app/app.component.html

希望能帮助到你!