I have successfully retrieved JSON data from a database using PDO in Angular. The data is being returned as expected when I encode it to JSON. However, I am facing an issue with displaying the data using ng-repeat in Angular.
Although the div
elements are showing up, the post.time
value is not being displayed.
HTML
<html ng-app="dataVis">
. . .
<body ng-controller="GraphController as graph">
<div ng-repeat="post in graph.posts track by $index">
{{post.time}}
</div>
</body>
</html>
JSON data
[
{
"time": "1340",
"postId": "282301",
"likes": "2"
},
{
"time": "1300",
"postId": "285643",
"likes": "0"
}
] . . . (etc)
JS
(function () {
var app = angular.module('dataVis', []);
app.controller('GraphController', ['$http', function ($http) {
var graph = this;
graph.posts = [];
$http.get('/query-general.php').success(function (data) {
console.log(data); // returns JSON data
graph.posts = data;
});
}]);
}());
In my initial code, I did not include track by $index
, but after encountering a duplicate error, I added it.
I am seeking assistance in properly displaying the JSON data on the HTML page using ng-repeat in Angular. Any help would be greatly appreciated!