I have a json that has the property categories[], and inside each categories there is a subCategories[]; and for eachsubCategories there is a subSubCategories. I would want to generate the dropdowns based on the given json structure.
{
"categories": [
{
"men": "Mens",
"subCat": [
{
"topWear": "Top Wear",
"subSubCat": [
{
"tshirts": "T-shirts",
"otherAttributes": [
{
"fitting": [
"type 1",
"type 2",
"type 3"
]
},
{
"washCare": [
"wash Care 1",
"wash care 2"
]
}
]
},
{
"shirt": "Shirt",
"otherAttributes": [
{
"fitting": [
"type 4",
"type 5",
"type 6"
]
},
{
"washCare": [
"wash Care 4",
"wash care 5"
]
}
]
}
]
},
{
"bottomWear": "Bottom Wear"
}
]
},
{
"women": "Women",
"subCat": [
{
"topWear": "Top Wear",
"subSubCat": [
{
"tshirts": "T-shirts",
"otherAttributes": [
{
"fitting": [
"w-type 1",
"type 2",
"type 3"
]
},
{
"washCare": [
"w-wash Care 1",
"wash care 2"
]
}
]
},
{
"shirt": "Shirt",
"otherAttributes": [
{
"fitting": [
"w-type 4",
"type 5",
"type 6"
]
},
{
"washCare": [
"w-wash Care 4",
"wash care 5"
]
}
]
}
]
},
{
"bottomWear": "Bottom Wear"
}
]
},
{
"kids": "Kids"
}
]
}
For example:
- Initially first drop-down should be populated with
mens,women,kidsoptions. - Next on main category selection, second drop-down should populate with
subCatoptions. - Next, on
subCatselection, third drop-down should populate withsubSubCatoptions.
How can I achieve this using angular?
ng-optionsto populate the dropdowns; when you select an option from the first dropdown, it'sng-modelwill be one of the objects from the first level of the array, along with all it's possible options for the secondng-options, and so on.