【问题标题】:Check all checkbox from table header angular 2选中表头角度 2 中的所有复选框
【发布时间】:2017-02-24 13:11:22
【问题描述】:

我有一个表格,第一列是复选框

<table *ngIf="Results && Results.length">
    <thead>
        <tr>
            <th>
                <input type="checkbox" name="all"  />
            </th>
            <th>Location</th>
        </tr>
    </thead>
    <tbody>
        <tr *ngFor="let Result of Results; let i = index">
            <td>
                <input type="checkbox" name="size1" value="{{Result.id}}" [checked]="Result.State" />
            </td>
            <td>{{Result.Column1}}</td>
        </tr>
    </tbody>
</table>

考虑到我在 Result.State 绑定中有来自数据库的数据是否已选中复选框,我如何在 Angular2 中实现检查全部并取消选中全部。 (这是有效的)。 我需要检查/取消检查用户是否手动输入以及是否检查了从数据库返回的所有项目。

【问题讨论】:

    标签: angular


    【解决方案1】:

    您可以在打字稿中创建方法:

    checkAll(){
       for(let i in this.results){
           this.results[i].State = true;
       }
    }
    

    并在某处点击时调用它,例如:

    <button (click)="checkAll()">Check all</button>
    

    【讨论】:

      猜你喜欢
      • 2017-08-27
      • 1970-01-01
      • 2015-10-29
      • 1970-01-01
      • 1970-01-01
      • 2019-09-18
      • 1970-01-01
      • 2017-11-26
      • 2018-08-25
      相关资源
      最近更新 更多