0

I am working on my first AngularJS web-app and have been stuck trying to iterate and parse some data. I am trying to display how many users (and ideally their name) are currently connected to my Firebase, aka {{users}}.

I am receiving the following output from AngularFire, but cannot parse or iterate through it.

Output from {{users}} (joe and james are both connected to the firebase)

{"b16b":"joe","e109":"james"}

Code within the main controller:

angularFire(fb_userRef, $scope, "users");

Attempting to display data and/or iterate through all the users: (fail)

<div class="panel right" data-role="panel" data-position="right" 
     data-display="overlay" id="right-panel">
<h3>{{users.length}} people here</h3>
<div ng-repeat="usr in users"><h1>YES</h1></div>

Any help would be very appreciated!

Frank van Puffelen
  • 418,229
  • 62
  • 649
  • 645
Joe Barreca
  • 49
  • 2
  • 7

1 Answers1

1

Looking by your users variable it is a object not an array. Use the key,value syntax of ng-repeat to iterate over it properties

<div ng-repeat="(key,value) in users"><h1>YES</h1></div>

Chandermani
  • 42,177
  • 11
  • 82
  • 86
  • Thank you very much! It worked perfectly. Is there a similar way to quickly get a count for all of the properties within the object? {{users.length}} seemed like it would work but it does not. – Joe Barreca Dec 25 '13 at 04:44
  • Not sure about that as the users is not an array. – Chandermani Dec 25 '13 at 05:00
  • This would help http://stackoverflow.com/questions/126100/how-to-efficiently-count-the-number-of-keys-properties-of-an-object-in-javascrip – Chandermani Dec 25 '13 at 05:01