Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

68
Views
Angular checkboxes into array

How to handle form input with checkboxes correctly? I have a form definition:

this.cargoSignupForm = new FormGroup({
        trucksToSelect: this.fb.array([])
      });

Submit function:

onSignupForCargo(cargoId: string) {
    this.cargosService.signupForCargo(
      cargoId,
      this.cargoSignupForm.value.trucksToSelect
    )
  }

and template:

<form [formGroup]="cargoSignupForm" (submit)="onSignupForCargo(cargo.id)" *ngIf="!isLoading">
                                      <div *ngFor="let truck of (trucksByCargoId.get(cargo.id)); let i = index">
                                        <mat-checkbox formControlName={{truck._id}} value={{truck._id}}>{{truck.regNumber}}</mat-checkbox>
                                      </div>
                                      <input type="submit" value="GO" class="button-basic">
                                    </form>

I want to export array of selected checkboxes(value must be truckId) to backend. Thank you for your time!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I see some problems here:

  1. trucksByCargoId.get(cargo.id) -- store this value in a const/var and pass that here .
  2. You are taking truck._id as value for mat-checkbox but you want cargo.id as output. Please refer to this link How to get the value from angular material checkbox
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!