I am working on a page that has 2 select lists, each populated by a call from a REST service:
var mainApp = angular.module('taxonomyViewer', []);
mainApp.controller('apiTaxonomyController', function ($scope, $http) {
$scope.taxonomyList = []; // the taxonomy list for the first select list
$scope.taxonomyStates = []; // the state list for the taxonomy selected in the first list
$http({
method: 'GET',
url: '/api/reports/taxonomies'
}).then(function (response) {
$scope.taxonomyList = angular.fromJson(response.data);
console.log($scope.taxonomyList);
});
$scope.update = function () {
$http({
method: 'GET',
// api/reports/taxonomies/{ent_id}/states
url: '/api/reports/taxonomies/' + $scope.selectedItem + '/states'
}).then(function (response) {
$scope.taxonomyStates = angular.fromJson(response.data);
console.log($scope.taxonomyStates);
});
console.log("selected item: " + $scope.selectedItem);
};
My select lists are here:
<div class="col-md-4">
<div ng-app="taxonomyViewer" ng-controller="apiTaxonomyController">
<select ng-model="selectedItem"
ng-options="items.ent_id as items.ent_desc for items in taxonomyList"
ng-change="update()">
<option value=""> Select Taxonomy </option>
</select>
</div>
<br />
<div ng-app="taxonomyViewer" ng-controller="apiTaxonomyController">
<select ng-model="selectedState"
ng-options="items.ens_guid as items.enk_name + ' - ' + items.sg_name for items in taxonomyStates"
ng-change="updateState()">
<option value=""> Select Taxonomy State </option>
</select>
<br />
</div>
<div id="taxonomyTree" class="fancytree-fade-expander">
</div>
</div>
When you select an item from the first list, the REST service is called and then the second list should populate. The REST service is getting called from inside the $scope.update function but the select list is not loading the $scope.taxonomyStates items.