I am trying to show a nested array in AngularJS. However, I can't get it to work.
Controller:
$scope.selected_category = [];
$scope.categories = [];
$scope.getCategories = function() {
ItemService.getCategories().success(function(categories) {
$scope.categories = categories;
});
}
$scope.getCategories();
The form setting $scope.selected_category
<select class="form-control" ng-model="selected_category">
<option ng-repeat="category in categories" value="{{ category }}">{{ category.name }}</option>
</select>
So... now printing {{ selected_category }} show the expected array with a subcategory array inside:
{
"id": "1",
"name": "clothing",
"subcategories": [
{
"id": "1",
"name": "jackets",
"item_category_id": "1"
},
{
"id": "2",
"name": "jeans",
"item_category_id": "1"
},
{
"id": "3",
"name": "sweaters",
"item_category_id": "1"
}
]
}
Hooowever, when I try to do selected_category.subcategories I get nothing. Why is that?
Here's a plunker with the reproduced problem: http://plnkr.co/edit/AtqpXogmItdSupEZGt7R?p=preview
category.nameand not the actual category object toselected_category