I have a controller:
app.controller("AllController", function($scope, $http){
$scope.listSkills = function() {
$http.get("/showSkills").success(function(skills_from_database){
$scope.skills = skills_from_database.list;
})
}
});
This is the html with both selects, but only the first one works:
<select name="skill_category" id="skill_category" form="AddSkillForm" onclick="showNewCatInput()">
<option value="newCat">New category</option>
<option ng-repeat="category in skills" value="{{category.categoryName}}">{{category.categoryName}}</option>
</select>
<select name="skill_subcategory" id="skill_subcategory" form="AddSkillForm" onclick="showNewSubCatInput()">
<option value="newSubCat">New subcategory</option>
<option ng-repeat="subcategory in category.subcategories" value="{{subcategory.subcategoryName}}">{{subcategory.subcategoryName}}</option>
</select>
So I know that to get all the subcategories I need the category selected on the first select, but I don't know how to do it. As I read, I think that I need to use ng-model, but even if I could connect the 2 selects, it would still not work the second one.
That is because I can't access the subcategory with this:
ng-repeat="subcategory in category.subcategories"
Simply because "category" doesn't exist there, so where it comes? from this other code that works:
<div ng-repeat="category in skills">
<h1>{{category.categoryName}}</h1>
<div ng-repeat="subcategory in category.subcategories">
<h2>{{subcategory.subcategoryName}}</h2>
</div>
</div>
As you can see, I know I have to access to "category in skills" first, but what I need is not all categories in skills, I need just the selected category.
So to summarize the problems:
Don't know how to use ng-model to bind 2 selects and don't know how to access the subcategories from the selected category
The json data and angular scope can be found in this other post that I made yesterday, there you can also see the html/angular code that works to get the category and subcategory. Stackoverflow post
selectedIndexvalue but I don't know how to do something with it.var category = document.getElementById("skill_category").selectedIndex;value="{{category}}"ng-repeat="subcategory in category.subcategories", but I don't know how to replace thecategory.subcategorieswith my variable category that has the index value. I explain in the post whycategory.subcategoriesdoesn't work