I have a data structure which consists of a parent category such as music. its title is defines in the object under hobbies[0].parent.title I want to have a ngFor which outputs this title out (I have no issues here), then under that there will be another nested ngFor dealing with the sub-genres which is under the hobbies[0].children[i] as an array - I would like to output these as checkboxes which is again no problem but the issue arises when I try to make them a reactive form, my basic need is to validate that at least 1 or 2 have been checked and to get the info of the checked item, with ReactiveForms I have a good idea how to achieve this without a nested json struct, its really throwing me off
I have tried a ton of different approaches in these articles but I cant seem to get it to work, any help much appreciated.
https://stackblitz.com/edit/form-array-3-levels
https://www.toptal.com/angular-js/angular-4-forms-validation
https://jenniferwadella.com/blog/managing-dynamic-and-nested-forms-angular
Ive been playing around with this for a few hours by my html has stayed the same
<form [formGroup]="form" action="">
<label *ngFor="let parent of fetchInterests; let i = index">
<div *ngFor="let item of parent.children; let i = index">
<ion-checkbox ></ion-checkbox> {{ item.title }} {{ item.selected }}
</div>
</label>
</form>
my json demo data is below
var hobbies = [{
"parent": {
"parentId": "dMGkZuB8JV",
"title": "Music",
"hero": "https://s3-eu-west-1.amazonaws.com/music/placeholder.jpg"
},
"children": [{
"title": "Jazz",
"hero": "https://s3-eu-west-1.amazonaws.com/music/placeholder.jpg",
"about": "",
"selected": false
}, {
"title": "Rock",
"hero": "https://s3-eu-west-1.amazonaws.com/music/placeholder.jpg",
"about": "",
"selected": false
}, {
"title": "Classical",
"hero": "https://s3-eu-west-1.amazonaws.com/music/placeholder.jpg",
"about": "",
"selected": false
}, {
"title": "Soul",
"hero": "https://s3-eu-west-1.amazonaws.com/music/placeholder.jpg",
"about": "",
"selected": false
}]
}, {
"parent": {
"parentId": "19h2yOfZaq",
"title": "computers and systems",
"hero": "https://s3-eu-west-1.amazonaws.com/it/placeholder.jpg"
},
"children": [{
"title": "data processing",
"hero": "https://s3-eu-west-1.amazonaws.com/it/placeholder.jpg",
"about": "",
"selected": false
}]
}, {
"parent": {
"parentId": "m2zQkAgOog",
"title": "African planes",
"hero": "https://s3-eu-west-1.amazonaws.com/outdoors/placeholder.jpg"
},
"children": [{
"title": "camping",
"hero": "https://s3-eu-west-1.amazonaws.com/outdoors/placeholder.jpg",
"about": "",
"selected": false
}, {
"title": "swimming",
"hero": "https://s3-eu-west-1.amazonaws.com/outdoors/placeholder.jpg",
"about": "",
"selected": false
}, {
"title": "hunting",
"hero": "https://s3-eu-west-1.amazonaws.com/outdoors/placeholder.jpg",
"about": "",
"selected": false
}]
}]