1

I have a function in my application that returns the first name of a user as a Firebase object:

function getFirstName(uid) {
    var userNameRef = Ref.child('users/' + uid + '/firstName');;
    return $firebaseObject(userNameRef);
}

Why can I only access $value from the HTML view, but not from a controller like this:

var firstName = getFirstName(uid);
$scope.firstName = firstName.$value;
Massimo Bortone
  • 611
  • 1
  • 9
  • 18
  • Possible duplicate of [Asynchronous access to an array in Firebase](http://stackoverflow.com/questions/27049342/asynchronous-access-to-an-array-in-firebase) – Kato Oct 14 '15 at 22:42

1 Answers1

4

You can access it in a controller, but it loads asynchronously so you'd have to use a promise. You should only do this if you absolutely need the value in your controller.

getFirstName(uid).$loaded().then(function(firstName) {
  console.log(firstName.$value);
});
Anid Monsur
  • 4,538
  • 1
  • 17
  • 24