0

I have an error that I don't understand with ReactiveForms.

output var from roomsGroup returns an array of object like I wish.

Then I use spread operator to pass all objects to the form group in roomingGroup. But only the first object is set.

I don't know what I have to do to make it work.

Any idea ?

export function roomingGroup (fb: any) {
    return fb.group(
        ...roomsGroup(fb)
    );
}

function roomsGroup (fb) {
    let output = [];

    for (let i = 1; i < 4; i++) {
        let nameOfProperty = 'R' + i;

        output.push({
            [nameOfProperty]: fb.group({
                quantity: fb.group({
                    adult: [''],
                    child: ['']
                })
            })
        })
    }

    return output;
}
Patrick Roberts
  • 49,224
  • 10
  • 102
  • 153
Swarovski
  • 581
  • 2
  • 8
  • 25

1 Answers1

0

I want output object. So I have to work with object :

let output = {};

for (let i = 0; i < count; i++) {
    let nameOfProperty = 'R' + (i + 1);

    output = (<any>Object).assign(output, {
        [nameOfProperty]: fb.group({
            quantity: fb.group({
                adult: [''],
                child: ['']
            })
    })})
}

return output;

That's my solution.

Swarovski
  • 581
  • 2
  • 8
  • 25