简体   繁体   English

AngularJS ng-repeat 不适用于选择选项

[英]AngularJS ng-repeat is not working with select option

My http part it work it get the value there is not problem with it but when i use them on select option it doesn't show it shows me in the inspect it shows all the values我的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>

you are saving a $http response object on $scope.populars, not an object array as you are expecting in the html snippet.您正在 $scope.populars 上保存 $http 响应对象,而不是您在 html 代码段中期望的对象数组。

I suggest:我建议:

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

Assuming the data your API responds has the form:假设您的 API 响应的数据具有以下形式:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM