Home > Software design >  Get formcontrol name of element in an FormArray
Get formcontrol name of element in an FormArray

Time:08-30

I am using FormArray in side a form. I am able to get fines which is of type FormArray by using code below but I am not able to get controls inside FormArray element. Is there any way to get controls inside FormArray element?

createForm(): void {
    this.transactionForm = this.formBuilder.group({
      date: [this.today],
      fines: this.formBuilder.array([]),
  
    });
}
  
  
  
get fines(): FormArray {
    return this.transactionForm.get('fines') as FormArray;
}

CodePudding user response:

It can be done by using index followed by get() with the name of the control which you would like to get :

    const lines = this.transactionForm.get('lines') as FormArray;
      
    // suppose you have a control with name notes then  
    console.log('notes', lines.controls[0].get('notes'));
  • Related