I'm having troubles retrieving the data from json file using the following structure. In my controller.js file I have:
var controllers = angular.module('hotels.controllers', []);
controllers.controller('AppCtrl', function ($scope, $http){
$scope.list;
$http.get('json-folder/name.json').success(function(data, status, headers, config) {
$scope.list = data.data;
console.log(data);
});
And in that name.json file I have the following structure:
{
"hotel": [
{
"id": 1,
"name": "Some hotel name",
"address": "123 Street",
"category" : [{
"id": 1,
"name" : "Category 1",
"bnb" : "yes",
"simple" : "some value",
"double" : "another value"
},
{
"id": 2,
"name" : "Category 2",
"bnb" : "no",
"simple" : "some value 2",
"double" : "another value 2"
},
{
"id": 3,
"name" : "Category 3",
"bnb" : "no",
"simple" : "some value 3",
"double" : "another value 3"
}
]
},
{
"id": 2,
"name": "Some hotel name 2",
"address": "33333 Street",
"category" : [{
"id": 1,
"name" : "Category 1",
"bnb" : "yes",
"simple" : "some value",
"double" : "another value"
},
{
"id": 2,
"name" : "Category 2",
"bnb" : "no",
"simple" : "some value 2",
"double" : "another value 2"
},
{
"id": 3,
"name" : "Category 3",
"bnb" : "no",
"simple" : "some value 3",
"double" : "another value 3"
}
]
}
],
"motel": [
{
"id": 1,
"name": "Some motel name",
"address": "321 Street",
"category" : [{
"id" : 1,
"name" : "Category Motel 1",
"bnb" : "yes",
"simple" : "some motel value",
"double" : "another motel value"
},
{
"id" : 2,
"name" : "Category Motel 2",
"bnb" : "no",
"simple" : "some motel value 2",
"double" : "another motel value 2"
}
]
}
]
}
and finally my html structure:
<div ng-controller="AppCtrl">
<ul class="pull-left">
<li class="pull-left" ng-repeat="hotel in list.hotels">
{{hotel.name}}
</li>
</ul>
</div>
<div ng-controller="CatCtrl">
<ul class="pull-right">
<li class="pull-right" ng-repeat="cat in list.categories">
{{cat.name}}
</li>
</ul>
</div>
I don't get anything back and I don't have any errors... What I want to have is one ul li with the name of the hotels and in another similar div I would like to have again list with categories names along with other data from categories under hotel. Please note that CatCtrl is the same as AppCtrl...
Any idea what I am doing wrong for first one, and what should I change in other controller to get what I need?
Thank you.
$scope.list = data.databe$scope.list = datainstead?datais meant to be the JSON itself alreadylisthas no propertieshotelsorcategories.. it hashotelandmotel. Not clear at all what you wantcategoriesarray to look like