我是 Angular JS 的新手,我对 ng-options 有疑问。这可能很愚蠢,但请帮我解决这个问题。我有以下 Controller ,用于检索国家/地区名称和值。我想将这些值分配给我的选择框。
function AddItemsController($scope, $http, $cookieStore, $location) {
var country_dropdown = "https://pier.com/api/app/dropdown_countries.html?contactid=2951&token=f6aa0dd18a206e40c3f68b154dd00ba0";
$http.get(country_dropdown).success(function(response) {
console.log(response); // [Object, Object, Object, Object, Object]
console.log(response[0].text); // America
console.log(response[0].value); //13
});
}
HTML
<div class="col-sm-10">
<span class="ui-select">
<select id="ai_exchange_member" ng-model="ai_exch_member" required ng-options=""></select>
</span>
</div>
我将如何做到这一点,而不是将静态列表添加到 HTML 中的选择中。
最佳答案
这样的东西应该可以工作(假设你的范围内有一个保存数据的模型):
$http.get(country_dropdown).success(function(response) {
$scope.model.aiExchange.options = response;
}
<select ng-model="model.aiExchange.value" ng-options="opt.text for opt in model.aiExchange.options">
</select>
关于javascript - 从 api 调用中检索 ng-options 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28382344/