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

363
Vistas
Fetch input values created by ngFor on button click Angular

I have an input field which is being generated using *ngFor and I want to capture all those values inside the input field on submit button click. I have tried all possible ways but not able to get the entered data, please help me. Below is my code I have tried.

html Code:

arr= [{name:"test", percentage: "29"},{name:"abc", percentage: "45"}, {name:"def", percentage: "63"}]


<div *ngFor= "let obj of arr">
<input type="text" [value]="obj.percentage">
</div>
<button (click)="submit()"></button>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Your current solution does not have any sort of form manager. There are two solutions:

Reactive Forms

// component.ts
form = new FormGroup( {
  test: new FormControl(null)
  // Add your other fields here
} );

// Patch your values into the form
arr.forEach(value => {
  this.form.get(value.name).patchValue(value.percentage);
})

// html
<div *ngFor= "let obj of arr">
  <input type="text" [formControl]="form.get(obj.name)" >
</div>

Your form will store all the values. To get them once, you could use form.value

NgModel

// component.ts
test: boolean;
// Add your other fields here

// Patch your values into the form
arr.forEach(value => {
  this.[value.name] = value.percentage;
})

// html
<div *ngFor= "let obj of arr">
  <input type="text" [(ngModel)]="obj.name" >
</div>

Both of these examples are cutting corners but they should give you enough of an idea of where to head next. I'd suggest the Reactive Forms path.

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