Search code examples
javascriptangularangular10

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


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)"

 <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>

Solution

  • Use your FormGroup (that you must have somewhere):

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

    This will give you the AbstractControl.