我在从REST API显示某些信息时遇到问题。每个location_id(2-7)都有自己的JSON数据。
如何获取每个location_id的数据显示。以下是我的代码:
控制器:
countryApp.controller('ViewLocation', function($scope, $http, $routeParams) {
$scope.localeID = $routeParams.localeID;
$http.get('http://localhost/slimtest2/location/' + $scope.localeID).success(function(data) {
$scope.location = data;
});
);
查看单个项目
<div ng-controller="ViewLocation">
Stuff
<div ng-model="location in location.location">
{{ location.location_id }}
</div>
</div
来自http://localhost/slimtest2/location/(location_id)的JSON数据。我目前有location_ids 2-7。
{ "location" :[{"location_id":"2","location_reference":"657821349","location_title":"Guam Premier Outlet,? ???? ???","location_category":"Shop,??","location_subcategory":"Shopping Mall,???","location_latitude":"13.489714","location_longitude":"144.781906","location_image":"gpo1.JPG","location_description":"Description test for GPO,GPO | ? ?? ?? ???","location_address":"Tamuning, 96913\r\nGuam | ?? ? , 96913\r\n?","location_village":"Tamuning","location_pricerange":"3","location_price":"100"}]}
答案 0 :(得分:0)
ng-model
用于输入类型,如输入字段,textarea,并且仅选择不用于div。您正在寻找ng-repeat
来迭代json对象
<div ng-repeat="loc in location.location">
{{ loc['location_id'] }}
</div>