Having trouble accessing a nested JSON object and displaying it using AngularJS. Need some guidance on this issue!
Here's the HTML:
<div id="ng-app" ng-controller="AnalyticsCtrl">
<div ng-repeat="post in posts">
<span>{{post.title}}</span>
<span>{{post.counter}}</span>
</div>
</div>
Looking to extract the post title and counter from the following JSON:
{
"status" : "success",
"data" :
{
"activeVisitors" : "148",
"posts" :
[
{
"id" : 1,
"title" : "Bla blabla blablabl bla blablaba",
"counter" : "20"
},
{
"id" : 2,
"title" : "Blie bla blup wflup flel del",
"counter" : "18"
},
{
"id" : 3,
"title" : "Flel djep flep tro fro klel",
"counter" : "14"
}
]
}
}
And here's the controller code:
'use strict';
var myApp = angular.module('myApp', []);
myApp.controller('AnalyticsCtrl', ['$scope', '$http', function($scope,$http) {
$http({method:'POST', url: 'jsonData.php', headers: {}})
.success(function(data) {
$scope.posts = data;
});
}]);