我必须根据用户ID在下拉列表中获取国家/地区。我已经尝试过下面的代码,但是它不起作用。有人可以帮我吗?
HTML:
<h1 align="center">Audit</h1>
<p>Country* :</p>
<select class="form-control flat-control-inner" id="" ng-model="user.id">
<option value = "" > --Please Select-- </option>
<option data-ng-repeat="c in countryList" ng-value="{{c.id}}" ng-selected="user.id==c.id">{{c.country}}</option>
</select>
控制器:
var user={};
$scope.user.id=1;
$scope.userId=1;
$scope.rgId=1;
$scope.ctryId=1;
$scope.trId=1;
$scope.ctyId=1;
$scope.fetchCountryList = function(userId){
$(".loader").show();
AuditorInfoService.fetchCountryList($scope.userId).then(function(response){
$scope.countryList = response.data;
console.log($scope.countryList);
},function(response){
$(".loader").fadeOut("slow");
});
};
$scope.fetchCountryList($scope.userId);
答案 0 :(得分:0)
您可以通过两种方式完成您想要的事情:
data-ng-repeat
中的ng-repeat
使用ng-options
。这是专门为select
<select class="form-control flat-control-inner" ng-options="c in countryList" ng-selected="user.id==c.id" ng-model="user.id"></select>
文档here