首页 > 解决方案 > AngularJS ng-repeat 不适用于选择选项

问题描述

我的http部分它工作它得到的值没有问题但是当我在选择选项上使用它们时它没有显示它在检查中显示它显示所有值

 $http({
        method: "GET",
        url: "php/home_page.php"
      }).success(function(result) {
        $scope.populars = result;
      });
<select  data-placeholder="Choose Location"  >

    <option  ng-repeat="reserve in populars"> {{reserve.name}}</option>

</select>

标签: javascripthtmlangularjs

解决方案


您正在 $scope.populars 上保存 $http 响应对象,而不是您在 html 片段中所期望的对象数组。

我建议:

 $http({
    // request info
  }).success(function(response) {
    $scope.populars = response.data;
  });

假设您的 API 响应的数据具有以下形式:

data = [
  {
    name: "data",
    // other object members
  }
]

推荐阅读