Binding an array of json results to html in angularjs -
i'm pretty new angularjs, , getting json result set i'd display. have following;
service:
var post = function(data) { angular.extend(this, data); } post.getall = function() { return $http.get('/api/posts').then(function(response) { var posts = []; for(var = 0; < response.data.length; i++) { posts.push(new post(response.data[i])); } return posts; }); };
controller method:
$scope.posts = posts.getall();
html view:
<ul ng-repeat="post in posts"> <li>{{ post.title }}</li> </ul>
the problem while repeats correctly, cannot access members of each object. eg: post.title or post.text not display. however, if use {{ post }} displays json entire result.
where going wrong here?
edit: i've seen comment below if use
post[0].title
it correctly displays, correct way displaying array of json results? i'd prefer use correct method, vs 1 "just works".
as per comments ranru , zack argyle, needed add index post, eg: post[0].title.
Comments
Post a Comment