How generate my reactiveform output angular

I do not know how to manipulate a formanray

I have with the select input:

example stackblitz

I want the output json like this:

json

{
  "comentario": "kkkkkkkkkkkk",
  "respuestas": [ { "idusuario": "",  "numero": "","iduser":"" } ] 
}

I get iduser from localstorage with that I have no problem

I found the how to do it

Update I make this little example but there a bug with select https://stackblitz.com/edit/angular-kj2ahg?file=src%2Fapp%2Fapp.component.html

728x90

1 Answers How generate my reactiveform output angular

Your form module (what you get from Formulario.value) does not need to match your data model.

Consider modeling your data as you need it coming from or getting saved to your data store. So in your example, with your iduser.

Then just map the data from your form data structure (Formulario.value) to your data structure.

Make sense?

For example, my data structure I want to send to my server could look like this:

export interface Product {
  id: number;
  productName: string;
  productCode: string;
  iduser: number;
}

I can copy the data from the form to this data structure like this:

const product = { ...this.myForm.value }; 

Then product contains all of the form fields. But, like in your example, the iduser is not on the form. So I can then use:

product.iduser = myUsersId;

To set the id. I then have a data structure I can pass to my backend.

2 weeks ago