I've got a working nested object on my form as follows:
this.form = this.fb.group({
name:(),
age:(),
address: this.fb.group({
city:(),
street:()
})
})
However, I want the possibility of having multiple addresses, in which case I would want the JSON to look like this:
{
"name": "name",
"age": "age",
"address":
{
"city": "cityA",
"street": "streetA"
},
{
"city": "cityB",
"street": "streetB"
}
How do I go about doing that?
Your JSON is not valid, it should be:
addressneeds to useFormArray. The below code shows:FormArray.FormGroupintoFormArray.The HTML template should look as below:
Sample StackBlitz Demo
Would suggest having a read and doing the practical by following Angular FormArray: Complete Guide.