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

159
Vistas
Select/Unselect and get values of dynamically generated checkbox using ngModel directive in Angular

I have a set of data response from an API and dynamically generating checkboxes on my HTML file using DataView component of PrimeNG.

The goal is to have a functionality where I can select/unselect all checkbox via button click and store their values in an array, for example.

Here's what I have so far;

Component HTML

<p-dataView [value]="requestList" {...} >
  <ng-template let-request pTemplate="listItem">
    <p-checkbox
      name="reqNo"
      inputId="reqNo"
      (click)="getCheckBoxValue()"
      value="{{ request.requestNo }}"
      [(ngModel)]="reqNo"
      [ngModelOptions]="{ standalone: true }"
    ></p-checkbox>
  </ng-template>
</p-dataview>

Main TS File

reqNo: any; reqNo is binded using ngModel.

Giving me arrays of values when consoled; ['R08000036', 'R08000002']

Each object in the API response looks like this;

{
  requestNo: "R08000036",
  requestBy: "SUPER_USER",
  requestTs: "2021-02-18T04:27:05.710+0000",
  collectTs: "2008-07-30T16:00:00.000+0000",
  testReason: "After Visit",
  noOfPrisoner: 2,
  status: "Printed",
  printTs: "2008-07-21T16:00:00.000+0000",
  escortingOfficer: "00552",
}

getCheckBoxValue event handler;

getCheckBoxValue() {
  console.log(this.reqNo);
}

I'm new to Angular and I think I'm using the ngModel wrong. Can someone please teach me?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can select all values by setting a new value for reqNo by values from requestList.

selectAll() {
  this.reqNo = this.requestList.map(item => item.requestNo);
}
unselectAll() {
  this.reqNo = [];
}

Example

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