Insert a value into a variable in the form

Asked

Viewed 39 times

0

I have a group and subgroup record.

My idGroup is receiving a value and I have to insert 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 must send this json:

{
    "name": "test", **<- Input que vou mandar no post**
    "groupItem": {
        "id": 1      **<- id que nao consigo enviar**
      }
}

2 answers

0


You can use the es6 Host spread

salvar() {
      this.service.postSubgroup({...this.formulario.value, id: this.idGroup});
}
  • I missed passing on the information about how I wanted the json, but it was a great help the answer.

0

My final code was :

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

Browser other questions tagged

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