I'm trying to reference child data within an object returned from a factory using Firebase, but I'm stumped. I can successfully get the user object that I want ($scope.user
), but I can't seem to reference the data inside of it (such as $scope.user.name
) - everything returns undefined.
app.factory('Data', ['$firebase', function(){
var ref = new Firebase('https://something.firebaseio.com/users');
return {
refUser: function(id){
return $firebase(ref.child(id)).$asObject();
}
}
}]);
app.controller('MainCtrl', ['Data', function(Data){
$scope.user = Data.refUser(123); // 123 = user ID
console.log($scope.user); // Returns user object successfully (containing 'name' key)
console.log($scope.user.name); // Return undefined
}]);
What is it that I'm missing? I'm not quite sure where the problem even lies with my understanding: Angular, Firebase, or simple javascript.