这是我的HTML代码
<body ng-app="mainApp">
<div ng-controller="myController">
<select>
<option ng-repeat="person in persons">{{ person.data }}</option>
</select>
</div>
</body>
这是我的JavaScript代码
var app = angular.module("mainApp", []);
app.controller("myController", function($scope, $http) {
$http.get("JSON URL")
.success(function(response) {
$scope.persons = response.data;
});
});
我的JSON URL采用这种格式[{"status": "success", "data": ["bank1","bank2","bank3"]}]
,我只想在下拉列表中显示“数据”列表,JSON数据中有太多银行,如何使用select和option?
答案 0 :(得分:0)
你可以这样做,
<强>控制器:强>
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>
<强> DEMO 强>