I'm using AngularFire, How can I retrieve this "email", "uid" data?

131 Views Asked by At

JS CODE

 var myFirebaseRef = new Firebase('https://blinding-inferno-7068.firebaseio.com/');
     var createdUserRef = myFirebaseRef.child('users').child('createdUser');
     $scope.users = $firebaseArray(createdUserRef);

HTML CODE

        <ul ng-repeat="user in users">
            <li>{{user.uid}}</li>
            <li>{{user.email}}</li>
            <li>{{user}}</li>
        </ul>

What I wanted was user.uid and user.email, but those thing didn't come out. So I checked the user object, and these things came out.

{"-Js0q1mWTwK-AZDZyVdc":{"email":"[email protected]","uid":"simplelogin:11"},"$id":"simplelogin:11","$priority":null}

How can I retrieve the key's value? (I mean email's value and uid's value)

Should I have to retrieve that data by putting code like this?

{{user.-Js0q1mWtwk-AZDZyVdc.email}}

like this ? horrible.

Please help me T_T..

1

There are 1 best solutions below

0
On BEST ANSWER

Let's have a look at your actual data:

{
  "users": {
    "createdUser": {
      "simplelogin:11": {
        "-Js0q1mWTwK-AZDZyVdc": {
          "email": "[email protected]",
          "uid": "simplelogin:11"
        }
      },
      "simplelogin:12": {
        "-Js0qpcW6jI9Yf3kplCs": {
          "email": "[email protected]",
          "uid": "simplelogin:12"
        }
      },
      "simplelogin:13": {
        "-Js0qrEbzYnFOOWtnCbg": {
          "email": "[email protected]",
          "uid": "simplelogin:13"
        }
      }
    },
    ...
  }
}
  • You can get such a dump of your data by new Firebase('https://blinding-inferno-7068.firebaseio.com/').once('value', function(s) { console.log(JSON.stringify(s.val())); }, function(e) { console.error(e); }) or by looking at the Data tab in the dashboard of your application.*

Your $firebaseArray contains objects such as this:

      "simplelogin:11": {
        "-Js0q1mWTwK-AZDZyVdc": {
          "email": "[email protected]",
          "uid": "simplelogin:11"
        }
      },

And there is no child email under simplelogin:11. So that's why you're not seeing that output.

It looks like you accidentally are adding the users with a $add operation, which creates the "-Js0q1mWTwK-AZDZyVdc" in the sample above. You should instead be using $save or just by using the regular Firebase JavaScript SDK:

ref.child('users/createdUser').child(user.uid).set(user);

Note that it is a bit tricky to explain without seeing the code you use to create those users. So if you edit your question to include that code, I'll update my answer.