Q:

Validation checks on dynamically created input text fields in angular

I check input text fields validations in angular normally by giving a template reference variable ngmodel to the input tag  such as 
  #name1="ngModel" then using that variable as such *ngIf="name1.touched && !name1.valid"
to check for its validity and display an error message accordingly.
However when i try to do this with dynamically generated fields, like for example if the user can choose to insert as many emails as they prefer, so they can choose to add one more field to add another email, i can generate these fields using ngfor however i can't perform the validity checks on them, as i can't assign a unique template reference variable ngmodel to each of the fields. Is there anyway to perform these checks on these fields? I am using angular 6.

A:

For validation you have better option of Reactive Form Validation in Angular.

However if you want to stick with same solution then you can use the same reference name within for loop since the context of reference of variable is within the loop and it will be different for each iteration.
Demo copy is here https://stackblitz.com/edit/angular-forloop-same-reference

