I having troubles to show in my view the content storage on Firebase DB. I know that Firebase is asynchronous. This is my current structure on my Firebase Database:
- Employees
- Recognitions
Code:
var bigObject = {};
// Find all recognitions
var ref = firebase.database().ref('recognitions');
ref.once('value').then(function(snapshot) {
bigObject = snapshot.val();
// Loop through all recognitions
for (o in bigObject) {
var ref2 = firebase.database().ref('employees').child(bigObject[o].employee);
ref2.once('value').then(function(snapshot2) {
bigObject[o].profile = snapshot2.val();
// Bind the content to the view
$scope.$apply(function() {
$scope.data = bigObject;
});
});
}
});
My concern is why are binding to my scope only the first element of bigObject? I guess that is an asynchronous error. How can solve that?.