0

我在这里遇到一种情况,我有一个包含多列的表和其中一列的复选框。

表结构

表结构

我试图将一些 formControlName 放在表格的复选框中。但控制台提示错误no value accessor for form control

<nz-table #filterTable [nzLoading]="loading" nzTitle="Assign a new role to the group" nzBordered>
      <thead nzSingleSort>
        <thead>
          <tr>
            <th nzShowSort nzSortKey="module">Module</th>
            <th></th>
            <th nzShowFilter [nzFilters]="filterrole" (nzFilterChange)="updateFilter($event)">Role</th>
            <th style="min-width: 120px;">Action</th>
          </tr>
        </thead>
      <tbody>
        <ng-container *ngFor="let module of listofmodules">
          <tr *ngFor="let role of module.role">
            <td>{{module.module}}</td>
            <td nzShowCheckbox [(nzChecked)]="role.checked" (nzCheckedChange)="refreshStatus(module.id, role)" name='tableCheck'
              id='tableCheck'>
            </td>
            <td>{{role}}</td>
            <td><a>View</a></td>
          </tr>
        </ng-container>
      </tbody>
    </nz-table>

有一个按钮可以将值提交到后端。在提交按钮(单击)功能中,我使用const formObj = this.validateForm.getRawValue();JSON.stringify将其转换为 JSON 格式。

我期望得到表中复选框的值。我该如何做到这一点?

预期结果

{"moduleid": "testing group 1", "roleheck":"Supervisor"}
4

1 回答 1

0

你不需要(nzCheckedChange)="refreshStatus(module.id, role)"。只需通过检查role.checked提交来过滤您的数据并将过滤后的数据传递到后端。参考

于 2018-12-26T12:07:20.510 回答