I have figured out how to populate the first dropdown menu from the database with Angular, but I am stuck on how to grab the selected value of the first dropdown box to query to populate the second box. Also, if the data is in separate tables, will I have to make an API call everytime a dropdown is selected? I have seen plenty of examples doing this with pre set tables, but not with actual api calls. This is where I get confused.
Here is what I have now.
app.controller('SelectOptGroupController', function($scope,$http) {
$http.get('api2.php').
success(function(data) {
$scope.animals = data;
});
$scope.species= [];
$scope.getOptions2 = function(){
//NOT SURE FROM HERE
};
})
HTML file
<div ng-controller="SelectOptGroupController" class="md-padding selectdemoOptionGroups">
<div>
<h1 class="md-title">Select Animal</h1>
<div layout="row">
<md-select ng-model="animals" placeholder="Animals" ng-change="getOptions2()">
<md-option ng-repeat="animal in animals" value="{{animal.animal}}">{{animal.animal}}</md-option>
</md-select>
<md-select ng-model="species" placeholder="Species">
<md-option ng-repeat="spec in species" value="{{spec.animal_species}}">{{spec.animal_species}}</md-option>
</md-select>
</div>
</div>
As of now the database has one table with two columns being animal and animal_species. There are multiple species of the same animal, for example there are three inserts with the animal name of bear but each of the animal_species are different grizzly, black, and polar. Thanks for any help!