1

I have an array of objects as below:

$scope.objects = [ { "artist": "bob", "title": "hey", "genre": "pop" }, { "artist": "mary", "title": "why", "genre": "pop" } ] 

I'm trying to iterate through them in my html as below:

<tr ng-repeat="object in objects"> <td>{{object.artist}}</td> <td>{{object.title}}</td> <td>{{object.genre}}</td> </tr> 

It's not working and it doesn't show anything.

What would be ideal is if I could turn that array of objects into just an Object. It seems like ng-repeat can iterate over that no problem.

Is there anyway to get this working? Or even better, is there a way to turn an Array of Objects into an Object that contains more objects?

Thanks!

EDIT - Adding specific details of my case below:

I set $scope.tracks = queryTracks();

function queryTracks() returns an array that I've logged to the console. The console log shows this:

[ {"artist":"Tiesto", "created":"2014-06-25T04:30:01.043Z", "genre":"trance", "imgurl":"http://www.youredm.com/wp-content/uploads/2012/11/tiesto-traffic-magik-muzik-youredm.jpg", "owner":"117", "rating":"", "readabledate":"Tue Jun 24 2014", "title":"Traffic", "trackid":"-JQGHErWDwOWfJsLMNSm", "yturl":"TpkUJfykRiA"} ] 

I've only listed one object in the above array, but the actual returned array contains many of these kinds of objects.

For some reason, ng-repeat is unable to parse and use the data.

6
  • 3
    That should work. Are you wrapping the <tr> in a <table> tag? Commented Jun 25, 2014 at 17:41
  • possible duplicate of using ng-repeat and ng-class on rows inside a table Commented Jun 25, 2014 at 17:44
  • In addition to checking the HTML, please make sure the iteration is actually within the scope of the right controller. Commented Jun 25, 2014 at 17:49
  • I've added an edit. It's within the right scope. I had this working before when I set $scope.tracks to equal an object that had more objects in it. It stopped working when I set $scope.tracks to equal an array of objects. Commented Jun 25, 2014 at 17:53
  • 1
    There must be something else going on, because what you've shown works fine: plnkr.co/edit/DGqd1YMN9N7osgMpM1Rg Commented Jun 25, 2014 at 18:00

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.