简体   繁体   中英

how to read content from form array in angular?

i have form array which input from user and then i want to read every single element from the form array and insert it into database using the web service but i''m unable to create a method for reading the element singularly . my form array code is as following :-

 createskillForm()
    {
      this.skillForm=this.formBuilder.group({
        skills:this.formBuilder.array([this.createskillFeild()])
      });
    }

and the create skill feild method is as follows :-

  createskillFeild():FormGroup
    {
      return this.formBuilder.group({
        skills:['',Validators.required]
      });
    }

please help me out as i'm unable to figure the method out?

You can access the form array control like:

let myfArr = this.skillForm.get('skills') as FormArray

To get all the values from the form array, you could probably use something like:

let arrValues = myfArr.controls.map(eachGroup => eachGroup.value);

arrValues will be an array of values of all the formGroups in the from array.

Edit

If you just want to get the values of the form array, you can simply do:

this.skillForm.get('skills').value

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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