1

I am trying to get all the data from firebase. I logged in successfully by authenticated users and I also got the response from the firebase for retrieving other information.

I attached my response here. enter image description here

When I try to read addInfo, address, categories, I get undefined but when I am try to read $id at that time I get it.

So, I am only able to get $id, I can not read other details.

    $scope.loggedInUserData = addOffersService.getBusinessDetails(idd,"");

Now when I use:

console.log($scope.loggedInUserData) 

then I get all the details.

But when I am trying to read

console.log($scope.loggedInUserData.addInfo); 
console.log($scope.loggedInUserData.address); 

I get undefined.

    function getBusinessDetails(id,path) {
        var query = db.child('/business/'+id+'/'+path);
        return $firebaseObject(query);
    }

What is wrong with the response?

AL.
  • 36,815
  • 10
  • 142
  • 281
Harish Mahajan
  • 3,254
  • 4
  • 27
  • 49

1 Answers1

0

Data is loaded from the Firebase database asynchronously. This means that when getBusinessDetails () returns, the data hasn't completed loading yet. So you're logging the object when the data hasn't loaded yet.

When you log $scope.loggedInUserData, the JavaScript console knowns that you're logging the entire object and ensures that it updates when the loading has completed.

But when you log $scope.loggedInUserData.addInfo, there is no value to log. So you see undefined in that case.

I recommend reading more about this here:

Community
  • 1
  • 1
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807