0

I have an issue where I can't retrieve a number value from a $firebaseObject in AngularFire.

if I console.log($scope.slideGen) the value correctly shows up in the log output of the entire object, but if I console.log($scope.slideGen.time) then I get undefined.

Got the following code in a controller

Auth.$onAuth(function(authData) {
      $scope.userKey = authData.uid;
      $scope.ref = Ref.child('users').child($scope.userKey);
      loadSlide();
    });

function loadSlide() {
      if ($scope.slideKey !== '') {

        $scope.slide = $firebaseObject($scope.ref.child('slides').child($scope.slideKey));

        $scope.slideGen = $firebaseObject($scope.ref.child('slidesGeneral').child($scope.slideKey));
        $scope.time = new Date(1970, 0, 1, 0, 0, 0).setSeconds($scope.slideGen.time);
        console.log('Current time set to: ' + $scope.slideGen.time); //This returns undefined
      }
    }
Chris
  • 6,719
  • 5
  • 35
  • 63
  • You haven't waited for the data to be fetched from the server. The client can't know the value until it is requested. – Kato Nov 11 '15 at 20:20
  • @Kato if I do a console.log($scope.slideGen); just above my other log statement it correctly returns the object – Chris Nov 11 '15 at 21:33
  • 1
    `console.log` is a notoriously bad way to troubleshoot asynchronous data loading, since it will "update" data in the console after it's been loaded. If you **must** use it, do `console.log(JSON.stringify($scope.slideGen));` But if you use `if (authData) loadSlide();` in your `$onAuth` handler, you'll be off to a better start. – Frank van Puffelen Nov 11 '15 at 21:59
  • Ok, thanks Frank, I will give that a go – Chris Nov 12 '15 at 12:56

0 Answers0