您可以使用ng-model
屬性將API json響應綁定到您的select
輸入。
鑑於你的HTML,我們得到這個選擇下拉列表,將綁定到person.timezone
。
<div ng-controller="MainController">
<select ng-model="person.timezone">
<option value="GMT-12:00">(GMT -12:00) Eniwetok, Kwajalein</option>
<option value="GMT-11:00">(GMT -11:00) Midway Island, Samoa</option>
<option value="GMT-10:00">(GMT -10:00) Hawaii</option>
<option value="GMT-9:00">(GMT -9:00) Alaska</option>
</select>
</div>
現在你需要的控制器實際調用REST服務,並得到了人員目標:
function MainController($scope, $http) {
/* query rest api and retrive the person
this of course would be replaced with the url of your actual rest call */
$http({method: 'GET', url: 'rest_api_response.json'}).success(function(data, status, headers, config) {
$scope.person = data;
// dont apply if were in digest
if(!$scope.$$phase)
$scope.$apply();
}).
error(function(data, status, headers, config) {
console.log("error retriveing rest api response");
});
}
對於此示例中,我只是做了一個名爲"rest_api_response.json"
文件,其中包含您的效應初探
{
"language" : "en_US",
"timezone" : "GMT-9:00"
}
Heres a plunker with the sample contained
下面的問題是否正確?由於它有3個降價,我不確定... – trainoasis