Extract the checkbox value within a table

I'm facing a challenge with a table that has multiple columns and a checkbox for one of the columns.

Table layout:

https://i.sstatic.net/qKZHt.png

I attempted to assign some formControlName to the checkbox within the table, but I received an error in the console stating that there is "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 submit button to send the values to the backend. In the (click) function of the submit button, I am using

const formObj = this.validateForm.getRawValue();
and utilizing JSON.stringify to convert it to JSON format.

I am looking to retrieve the value of the checkbox in the table. How can I achieve this?

EXPECTED RESULT

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

Answer №1

Instead of using

(nzCheckedChange)="refreshStatus(module.id, role)"
, you can simply filter your data by verifying role.checked upon submission and sending the filtered data to the backend. For more information, you can check out this helpful reference.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to adjust the font size for the label in mat-step?

Is there a way to update the design using only inline styles and CSS? Below is the code snippet I am working with: <div class="statusbar"> <mat-horizontal-stepper linear > <mat-step label="One" [complet ...

In which situations is it required to specify the return type of a function in TypeScript?

When it comes to making functions in typescript, the language can often infer the return type automatically. Take for instance this basic function: function calculateProduct(x: number, y: number) { return x * y; } However, there are scenarios where dec ...

The parameters 'event' and 'payload' do not match in type

Upon running the build command, I encountered a type error that states: Type error: Type '(event: React.FormEvent) => void' is not assignable to type 'FormSubmitHandler'. Types of parameters 'event' and 'payload&apos ...

The type definition file for '@wdio/globals/types' is nowhere to be found

I'm currently utilizing the webdriverio mocha framework with typescript. @wdio/cli": "^7.25.0" NodeJs v16.13.2 NPM V8.1.2 Encountering the following error in tsconfig.json JSON schema for the TypeScript compiler's configuration fi ...

Navigating with Angular: The URL for the home page should be set as http://localhost:4200/

I recently implemented URL routing in my project, but I have encountered an issue. Upon redirecting to the home page, the URL changes to http://localhost:4200/home. However, I would like the URL for the home page to simply be http://localhost:4200/ instea ...

Displaying data from a JSON object to a DOM table can be achieved by dynamically generating table columns based on the keys within

There is a JSON object that I'm working with: [ { "SysID": "4", "Defect Classification": "Wrong Image Color", "1": "3.0", "2": "", "3": " ...

Using Typescript to set a custom timeout duration based on a dynamic variable within a for loop

My function includes a timeout that changes every 3 seconds: setActiveImage(promotions) { for (let i = 0; i <= promotions.length - 1; i++) { setTimeout(()=> { this.activeImage = 'http://myrul/public/Commercials/' + promo ...

Develop a structured type that encompasses the stationary attributes of an object-oriented class

Provided are the following classes: class EnumerationDTO { designation: string; id: number; } class ExecutionStatusDTO extends EnumerationDTO { static readonly open: ExecutionStatusDTO = { id: 0, designation: 'Open' }; static readonl ...

Trouble with selectionChange event in mat-select component in Angular 13

I'm having trouble getting the selectionChange event to fire in my mat-select when the value is changed. html file <mat-select (selectionChange)="changeCategory()"> <mat-option *ngFor="let category of categ ...

Which is the best option: Service variable, Service Observable, or Service Subject?

Lately, I've been contemplating the idea of global variable declaration, and I'm struggling to see the advantage of using a Subject in a service instead of a simple variable or even an Observable. Could you help me understand why someone would ch ...

It is necessary to sign out users when a specific database value is set to false

Whenever a value in the firebase database is false, I need to shut down the app for maintenance purposes. A problem arises when the user is already logged in, as the function does not trigger unless I reload the app. I am looking for a way to trigger the f ...

Feeling overwhelmed by the potential capabilities of Angular Firestore

Seeking clarification as I am struggling to understand the usage of Angular and Firestore. Recently delved into Google Firebase and attempted CRUD operations with Firestore. What sets apart this library from others? import { Firestore } from '@angul ...

What is the best way to assign SnapshotChanges to an Observable Firebase variable?

I'm facing an issue where I can't access the id of a document even though it's visible when printing the object this.ressobj. However, when I try to use ressobj.id_doc in the card, the id of the document is not visible. this.ResColeccion ...

Can you tell me the appropriate type for handling file input events?

Using Vue, I have a simple file input with a change listener that triggers the function below <script setup lang="ts"> function handleSelectedFiles(event: Event) { const fileInputElement = event.target as HTMLInputElement; if (!fileInp ...

Leveraging an AngularJS service within Angular framework

I am trying to incorporate an AngularJS service into my Angular project. Below is my main.ts file: import {platformBrowserDynamic} from '@angular/platform-browser-dynamic'; import {AppModule} from './app/app.module'; import {UpgradeMo ...

Angular2 form refreshes instead of executing onSubmit()

Angular2 is not recognizing it as a form and not functioning as expected: <form (ngSubmit)="onSubmit(f.value, $event)" #f="ngForm"> <md-card-title>Settings</md-card-title> <md-card-content> <p> <md-input [(ngModel)]= ...

React with Typescript: Potential occurrence of an undefined object

While working with React and TypeScript, I encountered the error Object is possibly 'undefined' when using language.toLowerCase().includes(selectedCategory). To address this issue, I implemented a check as shown below. Although this resolved th ...

The angular httpTestingController.expectOne method throws an error, even when the httpClient's get method has

I have an issue with my testing in Angular. I am trying to test a simple function within a service: getReports(url: string): Observable<Report[]> { return this.http.get<Report[]>(url); } This is the test that I have written: it(`should c ...

Menu Navigation: Sequentially Colored Badges for Navigation Items

Within the MainService.ts file, there is a function that can alter the color set in badgesColorSet. The json config already defines 3 colors and the goal is for these colors to change each time the website is refreshed - for example, changing from red to g ...

Create categories for static array to enable automatic suggestions

I have a JavaScript library that needs to export various constants for users who are working with vscode or TypeScript. The goal is to enable auto-complete functionality for specific constant options. So far, I've attempted to export a Constant in th ...