0

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?

2
  • You are not showing anywhere your attempt to reading the element singularily? And what specifically does that mean, if I understand you correctly, you mean iterating the formarray? Commented Apr 22, 2019 at 11:00
  • @AJT_82 yes exactly Commented Apr 22, 2019 at 11:27

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.