AngularJS: ng-repeat get last 3 element from JSON


You could do

message in item.comments | limitTo:-3

Also for your comments, you should haven’t them as a object dictionary, rather just use an array like so:

"comments":[{"id":"comment1","name":"user1","description":"This is comment 1"},{"id":"comment2","name":"Jane D.","description":"This is comment 2"},{"id":"comment3","name":"Jone D.","description":"This is comment 3"},{"id":"comment4","name":"Test","description":"This is comment 4"},{"id":"comment5","name":"user","description":"This is comment 5"}]

If they aren’t already in order you may need to add a date field of sort and sort them after you pull them in.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s