简体   繁体   English

如何将表单控制器名称及其值传递给 Angular 10 中的函数?

[英]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.我想在下面的 Angular 输入字段上发生 focusout 事件时获取 formControllerName 及其值。 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)" (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>

Use your FormGroup (that you must have somewhere):使用您的FormGroup (您必须在某处拥有):

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

This will give you the AbstractControl .这将为您提供AbstractControl

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM