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

361
Views
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 answers
Answer question

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 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!