未从Promise值填充AngularJS ng-options

时间:2020-01-03 04:10:28

标签: angularjs angularjs-ng-options

我有一个选择框,用于绑定数据库中的数据。

<div class="select__wrapper-inner" data-ng-init="loadCountries()">
   <select id="country" ng-model="selectedCountry"
           ng-options="country.CountryName for country in countries">
      <option value="" selected>Select your option</option>
   </select>
</div>

下面是loadCountries函数

$scope.loadCountries = function () {       
    var resultList = mainService.loadCountries();
    resultList.then(function (response) {          
        $scope.countries = response.data;  
        $scope.selectedCountry = $scope.countries[0];
    });       
}

这也是正在使用的loadcountires代码

function mainService($http) {
    this.loadCountries = function () {
        var result = $http({
            method: 'GET',
            url: '/API/Country/Countries'               
        });
        return result;
    }
}

当我检查国家列表时,它正在成功填充,但未绑定到选择框中的ng-options。 谁能帮我这个忙!

0 个答案:

没有答案
相关问题