-2

In almost all the examples of ng-repeat I've seen, the data is structured like so:

$scope.dataCollected = [{name: bob, data: '10-12-12'}, {name:joe, data: '09-13-13'}];

However, the only way I can get ng-repeat to work is if I structure the data like this:

$scope.dataCollected = {bob: {name: bob, data: '10-12-12'}, joe: {name:joe, data: '09-13-13'}};

Structuring it as an array causes the ng-repeat to do absolutely nothing. It doesn't even give an error. Structuring it as an object containing objects works, but I'd like to use an array because I understand it's the only way to use a filter on ng-repeat.

I'm calling the ng-repeat like this:

<div class="list-row" ng-repeat="data in dataCollected">
  <h3 class="name"> {{data.name}} </h3>
</div>

What am I missing?

maskedjellybean
  • 689
  • 2
  • 9
  • 16
  • 1
    Check your console.. You might have got a syntax error there in your object. [Plnkr](http://plnkr.co/edit/5XUdqwds25MLEt3n6sxo?p=preview) – PSL Dec 29 '14 at 03:00
  • Hmm, it's not a syntax error. Both are readable by the console. – maskedjellybean Dec 29 '14 at 03:09
  • So why don't you use it as an array? – Shomz Dec 29 '14 at 03:10
  • I'd like to. The array is the version that doesn't work. – maskedjellybean Dec 29 '14 at 03:14
  • 1
    @maskedjellybean that is because i fixed in my plnkr. check the plnkr both works. i.e `{name: bob,` will throw error unless you have a variable named `bob`. if you think array syntax does not work please show us a demo showcasing the issue. – PSL Dec 29 '14 at 03:14
  • @Shomz Hope you read my reply for your comment on your deleted answer. :) – PSL Dec 29 '14 at 03:32
  • 1
    @PSL Yeah, wanted to undelete my answer to write it - sorry, I totally skipped the line where OP is actually showing the array, so I thought he wanted a quick way to filter it. – Shomz Dec 29 '14 at 03:33
  • 1
    @Shomz to be frank. i really have no idea what issue OP has... I even placed a plnk to show it works except for the syntax error. I have voted to close the question – PSL Dec 29 '14 at 03:34
  • 1
    @PSL You fixed it, I think that's all there was to it, we should close it. – Shomz Dec 29 '14 at 03:35

1 Answers1

0

Sorry guys, thank you for the help. The issue was that in an attempt to make my data easier to read, I had assigned names to the keys of the array using bracket notation as seen in the answer here: stackoverflow.com/questions/12244483/… ng-repeat does not like that at all. It seems the default keys are necessary.

Community
  • 1
  • 1
maskedjellybean
  • 689
  • 2
  • 9
  • 16