Firebase loop is looking for data

$scope.authorizedUsers = [];
fbRef.child('folders/').child($routeParams.folderID).once('value',
  function(ss) {
    ss.forEach(function(childSnapshot) {
  fbRef.child('users/').child(childSnapshot.name()).once('value',
    function(user) {
     $scope.authorizedUsers.push(user.val());
     console.log($scope.authorizedUsers);
    });
  });
});

I use the code above to search for the main data, and then loop it using ng-repeat

<div ng-repeat="user in authorizedUsers">{{user}}</div>

but displaying only cyclic data sometimes. Sometimes I have to update several times to get the data display.

Any idea or is there another better way to search for master data in firebase?

0
source share
1 answer

Callbacks are called asynchronously, so they do not occur within the scope of the Angular digest. Thus, they will not be applied to the page until a new compilation appears.

, angularFire , - $timeout(), Angular . . :

$scope.authorizedUsers = [];
fbRef.child('folders/').child($routeParams.folderID).once('value',
  function(ss) {
    ss.forEach(function(childSnapshot) {
  fbRef.child('users/').child(childSnapshot.name()).once('value',
    function(user) {
      $timeout(function() {
        $scope.authorizedUsers.push(user.val());
        console.log($scope.authorizedUsers);
      });
    });
  });
});
+1

Source: https://habr.com/ru/post/1569457/


All Articles