0
I am with a controller, where I search data firebase, but when doing this search the code suffers a delay and the page is loaded before with empty data before the query actually ends.
My controller :
function DashboardController($http, $scope){
var vm = this;
vm.searchJedi = searchJedi;
vm.obj = [];
vm.jedi = {
master: '',
name: '',
planet: '',
status
}
vm.teste = [];
vm.searchJedi();
function searchJedi(){
db.collection("jedi").get().then((querySnapshot) => {
querySnapshot.forEach((doc) => {
vm.jedi = doc.data();
vm.obj.push(vm.jedi);
});
console.log(vm.obj); //objeto com valor
});
console.log(vm.obj); //objeto vazio
}
}
What happens is that this last console is always empty while the console that is inside db.Collection comes filled after the search suffering a delay. Thus in the HTML page the data is not shown.
Any hint?