Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

70
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda