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.

Isaiah Lee
  • 647
  • 3
  • 9
  • 18
  • 3
    That should work. Are you wrapping the `` in a `` tag?
    – Jerrad Jun 25 '14 at 17:41
  • possible duplicate of [using ng-repeat and ng-class on rows inside a table](http://stackoverflow.com/questions/15410652/using-ng-repeat-and-ng-class-on-rows-inside-a-table) – zs2020 Jun 25 '14 at 17:44
  • In addition to checking the HTML, please make sure the iteration is actually within the scope of the right controller. – Fritz Jun 25 '14 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. – Isaiah Lee Jun 25 '14 at 17:53
  • 1
    There must be something else going on, because what you've shown works fine: http://plnkr.co/edit/DGqd1YMN9N7osgMpM1Rg – Jerrad Jun 25 '14 at 18:00
  • Sorry you're right. The format I had was fine. My mistake was unrelated, I was setting $scope.tracks outside of the function that was making the call to the server. I instead set the $scope.tracks in the callback function after the data was fetched and it works well now. – Isaiah Lee Jun 25 '14 at 19:36

0 Answers0