My service grabs JSON data and returns the data to the controller successfully, however I am having a problem using ng-repeat to iterate over the key names.
I want to display the key names on the page as a list as they are category names.
Currently ng-repeat iterates the correct number of times but it does not display the key name.
Controller:
app.controller('getNav', function(getJSONData, $scope) {
var path = 'json/navigation';
getJSONData.async(path).then(function(d) {
$scope.data = d;
});
});
Service:
app.factory('getJSONData', function($http) {
var getJSONData = {
async: function(path) {
var promise = $http.get(path).then(function (response) {
return response.data;
});
return promise;
}
};
return getJSONData;
});
JSON Data:
{
"data": {
"category_a": ["a", "b", "c", "d"],
"category_b": ["e", "f", "g"],
"category_c": ["h", "i", "j"]
},
"response": "Navigation"
}
View:
<ul ng-controller="getNav">
<li data-ng-repeat="(key, value) in data.data">Category name is: {{key}}</li>
</ul>