ng-repeat不能处理我的数据

时间:2017-03-17 13:35:05

标签: angularjs

以下代码运行正常。

<div class="row">
     <div class="well well-sm">{{roomdata.status}}</div>
</div>

但是当我使用ng-repeat时,没有显示任何内容

<div class="row">
     <div class="well well-sm" ng-repeat="x in roomdata.data">{{x.room_type}}</div>
</div>

这是我的数据

{
    status: 200,
    message: "Packages Found",
    data: [
        {
            room_type_id: "81",
            hotel_id: "72",
            room_type: "Deluxe",
            total_rooms: "5",
        }
    ]
}

编辑:对不起大家。这是我的坏事。我在$ http中放错了网址。它现在工作正常。谢谢大家

3 个答案:

答案 0 :(得分:2)

你可以尝试删除这些类(well well-sm )然后尝试打印,有时UI用户提供的类会产生问题

答案 1 :(得分:1)

您的代码似乎没有问题。但是如果您在数据阵列上有重复的对象,则在ng-repeat

中使用track by $index

&#13;
&#13;
angular.module("app",[])
.controller("ctrl",function($scope){

  $scope.roomdata = {  
   status:200,
   message:"Packages Found",
   data:[  
      {  
         room_type_id:"81",
         hotel_id:"72",
         room_type:"Deluxe",
         total_rooms:"5"
      }
   ]
 }
})
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
 <div class="row">
     <div class="well well-sm" ng-repeat="x in roomdata.data track by $index">{{x.room_type}}</div>
</div>
</div>
&#13;
&#13;
&#13;

答案 2 :(得分:1)

请尝试此代码..

angular.module("myApp", [])
  .controller("MyController", function($scope) {
    $scope.roomdata = {
    status: 200,
    message: "Packages Found",
    data: [
        {
            room_type_id: "81",
            hotel_id: "72",
            room_type: "Deluxe",
            total_rooms: "5",
        }
        ,
         {
            room_type_id: "81",
            hotel_id: "72",
            room_type: "Deluxe100",
            total_rooms: "5",
        }
    ]
}
  });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp">
  <div ng-controller="MyController">
   <div class="row">
     <div class="well well-sm" ng-repeat="x in roomdata.data">{{x.room_type}}</div>
</div>
  </div>
</div>