0

I am trying to find out if the input element in the iteration of a for(*ngFor) loop iteration is dirty but I cannot find a way to dynamically name the validation variable, therefore cannot get the outcome I am looking for.

<tr *ngFor="let user of users">
  <td>
    <div class="row">
      <div class="col-sm-10">
         <input id="{{user.id}}" class="form-control" [(ngModel)]="user.name" #[user.id]="ngModel" />
      </div>
      <div class="col-sm-2">
         <button *ngIf="[user.id].dirty" class="btn btn-success">Save</button>
      </div>
    </div>
  </td>
</tr>
1
  • please give brief description what you exactly want? Commented Apr 3, 2017 at 14:16

1 Answer 1

1

Validation properties can be found on AbstractControl instances. So you need to mark your form tag and then get a particular control from its controls property:

<form #myFrom="ngForm">
    <input name="myInput{{user.id}}">
    {{ myForm.controls['myInput' + user.id]?.dirty }}
</form>
Sign up to request clarification or add additional context in comments.

2 Comments

Ok but how would I apply this to a butt9n like in my example
You can use the "myForm.controls..." (boolean) expression in the *ngIf of the button.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.