I have a codepen of some code I am playing with. I want to load the json data through a service and then use ng-repeat to load the arrays.
The problem is that it loads the first array just fine. However, the nested array "data.cities" doesn't show up. In the console, it states that its too much recursion. Here is the link and code below.
html
<div ng-app="myApp" ng-controller="nameController">
<div class="container">
<div class="row">
<div class="col-md-12">
<div ng-repeat="r in data">
<div>{{ r.region }} - x: {{ r.x}}, y: {{r.y}} ---- {{ r.desc}}</div>
<div ng-repeat="city in data.cities">{{city.name}}</div>
<div>
</div>
</div>
</div>
</div>
</div>
JS
var app = angular.module("myApp", []);
app.controller("nameController", function($scope, mapService) {
$scope.data = mapService.mapData();
});
app.service("mapService", function() {
var mapInfo = [{
region: "America",
desc: "Some info about America",
x: 50,
y: 200,
cities: [{
name: "Chicago",
x: 20,
y: 232
}, {
name: "Los Angeles",
x: 52,
y: 124
}]
}, {
region: "Europe",
desc: "Some info about Europe",
x: 10,
y: 24,
cities: [{
name: "Chicago2",
x: 20,
y: 232
}, {
name: "Los Angeles2",
x: 52,
y: 124
}]
}, {
region: "China",
desc: "Some info about China",
x: 88,
y: 126,
cities: [{
name: "Chicago3",
x: 20,
y: 232
}, {
name: "Los Angeles3",
x: 52,
y: 124
}]
}];
this.mapData = function() {
/*angular.forEach(pics, function(value, key) {
//console.log("key", value.name);
return value.name;
});*/
return mapInfo;
};
});