0

I have a situation here where I have a table with multiple column and a checkbox for one of the column.

Table structure

Table structure

I've tried to put some formControlName in the checkbox in the table. but the console prompt an error that 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>

There is a button to submit the value to the back end. in the submit button (click) function, I am using the const formObj = this.validateForm.getRawValue(); and using the JSON.stringify to turn it into JSON format.

I am expecting to get the value of the checkbox in the table. How do I achieve this ?

EXPECTED RESULT

{"moduleid": "testing group 1", "roleheck":"Supervisor"}
James Z
  • 12,209
  • 10
  • 24
  • 44
ameruddin jamil
  • 155
  • 4
  • 18

1 Answers1

0

You don't need (nzCheckedChange)="refreshStatus(module.id, role)". Just filter your data by checking role.checked on Submit and pass filtered data to backend. Reference

Parshwa Shah
  • 331
  • 4
  • 14