Cannot access Firebase object attributes. Value displayed as undefined ANGULARFIRE

前端 未结 1 1079
暗喜
暗喜 2021-01-13 21:05

I want to do a custom login for a demo of my doing, but I encountered a problem.

I use the username to access a reference url inside Firebase, I get a returned objec

1条回答
  •  执笔经年
    2021-01-13 21:44

    Firebase values are loaded asynchronously. The value will not yet have been loaded into $scope.returnedObj when the alert fires.

    There are a couple of ways to handle values loading asynchronously from Firebase, for example using $loaded to get a promise:

    $scope.returnedObj.$loaded().then(function () {
      alert($scope.returnedObj.name);
    });
    

    The value is displayed in the template because Angular watches all $scope variables for changes. When the value is loaded (milliseconds later), it is immediately displayed.

    0 讨论(0)
提交回复
热议问题