title: How to Get Value and Do Validation of Input inside *ngFor Angular
body: <p>I have a Form (multiple Input fields) inside <code>ngFor</code> and i want to get values and validate them and add them to Users array to send it back to API. </p>
  
  <pre><code>  &lt;form [formGroup]="registerForm" (ngSubmit)="onSubmit()"&gt;
      &lt;div *ngFor="let user of users"&gt;
        &lt;div class="form-group"&gt;
            &lt;label&gt;First Name&lt;/label&gt;
            &lt;input type="text" formControlName="firstName" class="form-control" [ngClass]="{ 'is-invalid': submitted &amp;&amp; f.firstName.errors }" /&gt;
            &lt;div *ngIf="submitted &amp;&amp; f.firstName.errors" class="invalid-feedback"&gt;
                &lt;div *ngIf="f.firstName.errors.required"&gt;First Name is required&lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class="form-group"&gt;
            &lt;label&gt;Last Name&lt;/label&gt;
            &lt;input type="text" formControlName="lastName" class="form-control" [ngClass]="{ 'is-invalid': submitted &amp;&amp; f.lastName.errors }" /&gt;
            &lt;div *ngIf="submitted &amp;&amp; f.lastName.errors" class="invalid-feedback"&gt;
                &lt;div *ngIf="f.lastName.errors.required"&gt;Last Name is required&lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          &lt;button [disabled]="loading" class="btn btn-primary"&gt;Register&lt;/button&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>.ts</p>
  
  <pre><code>export class AppComponent  {
    users=[ 
      {id: 1},
      {id: 2},
      {id: 3}
    ]
  
  
    registerForm: FormGroup;
    submitted = false;
    constructor(private formBuilder: FormBuilder){
      this.registerForm = this.formBuilder.group({
        firstName: ['', Validators.required],
        lastName: ['', Validators.required]
      });
    }
  
    get f() { return this.registerForm.controls; };
  
    onSubmit() {
      this.submitted = true;
      // stop here if form is invalid
      if (this.registerForm.invalid) {
          return;
      }
      console.log(this.registerForm.value) // here i am getting value from last edited index.
    }
  }
  </code></pre>
  
  <p>Edit:
  <a href="https://stackblitz.com/edit/angular-nxqbjq" rel="nofollow noreferrer">Stackblitz Exmple</a></p>