Skip to content

Question: How can the forms plugin update a form array of objects? #1844

@markwhitfeld

Description

@markwhitfeld

Originally posted by @irowbin in #1745 (comment) on 10 May 2021

Hi there, I have been struggling to patching the state of FormArray values using this plugin.

I have something like this in component:

fg = this.fb.group({
 anyTerms: this.fb.array([this.fb.group({ term: [] })]),
})

now if I add more than one object in that array, it populates state values as [{term:'1'}, {term:'2'}] but it can't be populated from state to FormArray

The structure like this requires to create an AbstractControl but couldn't find a way to do from the state to component.

example:

[{term:'1'}, {term:'2'}].forEach(obj => this.controls.push(this.fb.group(obj)))

Is it done internally or something?

Looks like it was updated using this line which only care about raw value.

Can we have type check and patch value instead of raw?

Thanks,
Regards.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions