0

I have the following formarray (inside a parent: formgroup):

someArray: this.fb.array([
{
   someGroup: this.fb.group(
   {name: 'value', type: 'value2;}
   )
}

My html looks as follows:

<fieldset formArrayName="someArray">
  <div *ngFor="let someValue of parents.controls.someArray.controls; let x = index" >

    <div [formGroupName]="x">
     <fieldset formGroupName="someGroup">

I get the following error:

Cannot find control at someArray -> 0 > someGroup

I would expect that at index 0 in someArray, there is a formGroup somegorup therefore I can add a fieldset in the html for it. However this isn't the case. Can somebody explain why?

Cheers

1 Answer 1

1

That's because you created FormArray of one FormControl with the value:

{
   someGroup: this.fb.group(
     {name: 'value', type: 'value2}
   )
}

What you're looking for is:

someArray: this.fb.array([
   this.fb.group({
      someGroup: this.fb.group(
        { name: 'value', type: 'value2' }
      )
   })
])

Notice this.fb.group when constructing element for FormArray.

Ng-run Example

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.