Angularjs (1.5.8) - How Do I Populate A Select Option List Directly From Within Controller That Gets A Json Object?
I have an AngularJS app that I want to populate a select drop down list from a JSON result. The controller code gets the json but how do I populate the $scope.states. My drop down
Solution 1:
You can do this using ng-options
,
<select ng-model="selectedItem" ng-options ="s.name for s in states"></select>
Controller:
function($scope, $http) {
$http.get('test.json').then(function (response){
$scope.states = response.data;
console.log(response);
});
Solution 2:
You should be using ng-options for this.
Depending on what you want to show:
<select ng-options="state as state.name for state in states track by state.abbreviation" ng-model="accountAddresses.shippingState"></select>
Post a Comment for "Angularjs (1.5.8) - How Do I Populate A Select Option List Directly From Within Controller That Gets A Json Object?"