以下代码运行正常。
<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中放错了网址。它现在工作正常。谢谢大家
答案 0 :(得分:2)
答案 1 :(得分:1)
您的代码似乎没有问题。但是如果您在数据阵列上有重复的对象,则在ng-repeat
中使用track by $index
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;
答案 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>