I need to have a formControl for two different arrays under the same node so I could add and delete a respective nested node in the given Reactive form.
Expected JSON Format:
{
"title": null,
"days": [
{
"date": null,
"nodes": [
{
"type": "leg",
"from": null,
"to": null
},
{
"type": "activity",
"category": null
}
]
}
]
}
I have implemented control on day and node for which I was able to add and delete the form fields respectively however I need separate controls for type leg and activity under nodes.
Is there any way to implement nested formControl in here?
Update: Need two formgroups under a form array, please help to implement in HTML.
initX() {
return this.fb.group({
'date': [],
'nodes': this.fb.array([
this.initY(),
this.initZ()
]),
});
}
initY() {
return this.fb.group({
'type': ['leg'],
'from': [],
'to': []
})
}
initZ() {
return this.fb.group({
'type': ['activity'],
'category':[],
'cost':[]
})
}
Error: Cannot find control with path: 'days -> 0 -> nodes -> 1 -> from'
Can find the stackblitz of the sample code here: https://stackblitz.com/edit/angular-ivy-fkgxrr