Reputation: 159
This is my HTML code
<body ng-app="mainApp">
<div ng-controller="myController">
<select>
<option ng-repeat="person in persons">{{ person.data }}</option>
</select>
</div>
</body>
This is my JavaScript code
var app = angular.module("mainApp", []);
app.controller("myController", function($scope, $http) {
$http.get("JSON URL")
.success(function(response) {
$scope.persons = response.data;
});
});
My JSON URL is in this format [{"status": "success", "data": ["bank1","bank2","bank3"]}]
, I want only "data" list in drop down, there is too many banks in JSON data, How to use select and option?
Upvotes: 1
Views: 1335
Reputation: 222702
You can do this,
Controller:
app.controller("dobController", ["$scope", "$http",
function($scope, $http) {
$http.get("test.json").then(function(response) {
$scope.data = response.data[0].data;
console.log($scope.data);
})
}
]);
HTML:
<body ng-controller="dobController">
<select class="form-control" id="selection" ng-model="currentSelected" ng-options="selection as selection for selection in data"></select>
</body>
Upvotes: 0