2015-02-07 59 views
0

我是Angular JS的新手,我對ng選項有疑問。這可能很愚蠢,但請幫我整理一下。我有以下控制器檢索國家名稱和值。我想將這些值分配給我的選擇框。從api中檢索ng選項的值

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中添加靜態列表來選擇。

回答

1

像這樣的東西應該工作(假設你有保存數據在你的範圍模型):

$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>