Organiccat
Organiccat

Reputation: 5651

Combine two $firebaseArrays into single object using javascript or angularfire

I'm working in Angular (angularfire) trying to combine two firebaseArrays into a single object, but the asynchronous nature of the return calls is making it difficult. I would like to do something simple like:

$scope.itemStats = $firebaseStorage.getArray('item-stats');
$scope.stats = $firebaseStorage.getArray('stats');
$scope.newArray = $scope.itemStats.concat($scope.stats);

The code for the getArray function is:

getArray: function(key) {
  var dbRef = ref.child(key);
  return $firebaseArray(dbRef);
}

It's possible I'm querying the data wrong in the first place, and could grab both at the same time which would also solve my problem (aka, I'm asking the wrong question).

Which approach should I use, and how do I solve this?

Upvotes: 0

Views: 248

Answers (1)

Ron Harlev
Ron Harlev

Reputation: 16673

You can use the $loaded which will return a promise resolved when loading the array is done.
An example from the documentation

var list = $firebaseArray(ref);
list.$loaded()
  .then(function(x) {
    // now "list" is loaded
  })

Upvotes: 1

Related Questions