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

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -