Let's simplify it. I have two dropdown menus. Once a user selects a category from the first dropdown, another dropdown menu with subcategories should appear.
However, there seems to be an issue as the subcategory dropdown is always empty.
The JSON data for categories (vm.categories):
[
{
"doctype":"1120",
"description":"bla bla",
"subcategories":[
{
"@id":1,
"subcategory":"1",
"description":"New Offer",
"templates":[
{
"template":"12",
"description":"asfafasga",
"deliveryChannels":[
]
}
]
},
{
"@id":2,
"subcategory":"2",
"description":"New Offer",
"templates":[
{
"template":"1121",
"description":"asfag",
"deliveryChannels":[
{
"deliveryType":"4",
"description":"Test"
}
]
}
]
}
]
}
]
HTML code:
<div class="row">
<div class="col-sm-12">
<!-- Categories -->
<label for="category-select"><b>Category </b></label>
<select name="category-select" ng-model="vm.selectedCategory" required>
<option value="" disabled>--- Please select a category ---</option> <!-- not selected / blank option -->
<option value="{{category}}"
ng-repeat="category in vm.categories">
{{category.description}}
</option>
</select>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<!-- Sub Categories -->
<label ng-show="vm.selectedCategory" for="subcategory-select"><b>Sub-Category </b></label>
<select name="subcategory-select"
ng-show="vm.selectedCategory"
ng-model="vm.selectedSubCategory">
<option value="" disabled>--- Please select a sub-category ---</option> <!-- not selected / blank option -->
<option value="{{subCategory}}"
ng-repeat="subCategory in vm.selectedCategory.subcategories">
{{subCategory.description}}
</option>
</select>
</div>
</div>
Any thoughts on why this issue is occurring? It seems I can't access the subcategories array within the selected category.
EDIT: When I include
<span>{{vm.selectedCategory}}</span>
in the HTML, it displays the JSON data correctly. However, if I use <span>{{vm.selectedCategory.subcategories}}</span>
, it's returning null.
Another edit: Even
<span>{{vm.selectedCategory.doctype}}</span>
is showing null.