I've seen numerous examples of angularjs using JSON data to populate options in a select dropdown, but after numerous attempts and variations I still end up with a blank dropdown menu. I'm sure there's something wrong with my object naming convention, as all the angular examples are pretty confusing (what's plural? what isn't? etc.) Any help you can offer would be greatly appreciated.
JSON example:
{"fields":[
{"state": "OH",
"gender": "male"},
{"state": "OH",
"gender": "female"},
{"state": "IN",
"gender": "male"}
]};
html:
<div class="input-field col s12 m4" ng-app="totalQuery" ng-controller="queryCtrl">
<select multiple>
<option ng-repeat="fields in myData">{{fields.state}}</option>
</select>
<label>First Category</label>
</div>
<div class="input-field col s12 m4" ng-app="totalQuery" ng-controller="queryCtrl">
<select multiple>
<option ng-repeat="fields in myData">{{fields.gender}}</option>
</select>
<label>Second Category</label>
</div>
angularjs:
<script>
var app = angular.module('totalQuery', []);
app.controller('queryCtrl', function($scope, $http){
$http.get("file.json").then(function(response){
$scope.myData = response.data.fields;
});
});
</script>