Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to set value of a form control which is inside a form array in Angular reactive form

I’ve a reactive form:

    this.leDetailsUpdateForm = new FormGroup({
      entityNameArray: new FormArray([
        new FormGroup({
          id: new FormControl(),
          entityName: new FormControl(),
          entityNameStartDate: new FormControl(), // <----- this i want to set
          entityNameEndDate: new FormControl(),
          entityNameStatus: new FormControl(),
          status: new FormControl(),
        }),
      ]),
    })

I’m trying to set it after some calculations as follows :

  setStartDates(e: any) {
    console.log(e);
    this.leDetailsUpdateForm.get('entityNameArray').get('entityNameStartDate').setValue(e)
  }

I’m not getting the required syntax on google. Please help.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

you can access FormArray controls by index only so you can try something like

this.leDetailsUpdateForm.controls['entityNameArray'].controls[0].controls['entityNameStartDate'].setValue(e)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading