在API调用中,我收到一个如下所示的对象并将其分配给$scope.countries
:
$scope.countries = {
AU:"Australia",
BE:"Belgium",
US:"United States"
}
在我的前端,我想将每个国家/地区添加到下拉列表中,以便显示如下所示的完整国家/地区名称。我采取了许多不同的方法,但无法使其发挥作用。
- Australia
- Belgium
- United States
请参阅下面的代码:
<select ng-options="(key, value) in countries" ng-change="getRoles()">
答案 0 :(得分:0)
使用"ng-repeat = item in countries"
和ng-options={{item}}
答案 1 :(得分:0)
试试这个,
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.countries = {
AU:"Australia",
BE:"Belgium",
US:"United States"
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js"></script>
<body ng-app="plunker" ng-controller="MainCtrl">
<select ng-model="country" ng-options="key as value for (key , value) in countries"></select>
</body>