Search code examples
angularangular-forms

How to detected which input fields in my formGroup is on blur, Angular 9


I have a form with formgroup, I put blur event on every input on my form.

How can i detect which specific inputs on blur ??

html file:-

<input type="text" class="form-control" formControlName='bankAccountNumber' (blur)="updateCompanyInfo($event)" required>

<input type="text" class="form-control" formControlName='phoneNumber' (blur)="updateCompanyInfo($event)" required>

ts file :-

  updateCompanyInfo($event) {

  }

Solution

  • <input type="text" class="form-control" formControlName='bankAccountNumber' (blur)="updateCompanyInfo($event, bankAccountNumber)" required>
    
    <input type="text" class="form-control" formControlName='phoneNumber' (blur)="updateCompanyInfo($event, phoneNumber)" required>
    

    Take the second parameter if you want to use some logic.

    If it's just assigning then no need to do anything as formcontrol will have the respective value