How to set value in a formBuilder.array in Angular?

Asked

Viewed 80 times

0

Using relative forms at angular 4, I have a problem defining a value for the array. How to set its value ?

marketStructures: this.formBuilder.group({
 include: this.formBuilder.group({
  departments: this.formBuilder.array([ this.createItem() ])
 })
})

createItem(): FormGroup {
    return this.formBuilder.group({
      code: '',
    });
  }


this.formulario.patchValue({
      'departments': { code: '01' }
    })

1 answer

1


Because it is an array vc has to set the interim array or to set a value only use the at method

this.formulario.patchValue({
      'departments': [{ code: '01' }]
    })

or else

this.formulario.get('departments').at(0).patchValue({ code: '01' })

Browser other questions tagged

You are not signed in. Login or sign up in order to post.