Insert a value into a variable in the form

0

I have a group and subgroup register.

My idGroup is getting a value and I have to enter it in the form to go in the post.

@Input() idGrupo: any;

configurarFormulario() {
    this.formulario = this.formBuilder.group({
      name: [null, Validators.required],
      groupItem: this.formBuilder.group({
         id: []
      })
    });
 }

  salvar() {

    this.service.postSubgroup(this.formulario.value);
    console.log(this.formulario.value);
   // console.log('O id do grupo é esse: ${this.idGrupo}');
  }

He should send this json:

{
    "name": "test", **<- Input que vou mandar no post**
    "groupItem": {
        "id": 1      **<- id que nao consigo enviar**
      }
}
    
asked by anonymous 07.08.2018 / 02:43

2 answers

0

You can use the es6 operator spread

salvar() {
      this.service.postSubgroup({...this.formulario.value, id: this.idGroup});
}
    
07.08.2018 / 09:45
0

My final code stayed:

this.service.postSubgroup ({       ... this.formulario.value,       groupItem: ({         id: this.idGroup       })     });

    
07.08.2018 / 20:33