Home > Mobile >  How to pass Form controller name and its value to a function in Angular 10?
How to pass Form controller name and its value to a function in Angular 10?

Time:11-14

I want to get the formControllerName and its value when focusout event happens on the below Angular input field. I have a Form with huge number of input fields like the below example. So, I want to do some operations on all input fields with respect to the Form controller. So, I want to try something like

(focusout)="passdataFunction(formControlName , formControlName.value)"

Please help me to sort this out.

<mat-form-field appearance="outline">
  <mat-label>Designation<span class="redColor">*</span></mat-label>
  <input 
    matInput 
    formControlName="Delegate_designation" 
    id="Delegate_designation" 
    #Delegate_designationValue  
    placeholder="Designation in the Company"
  >
</mat-form-field>

CodePudding user response:

Use your FormGroup (that you must have somewhere):

(focusout)="passdataFunction(formGroup.get('formControlName'))"

This will give you the AbstractControl.

  • Related