I'm having a controller, where I look for data from the firebase, but when doing this search the code undergoes 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 the db.collection is populated after the search undergoing a delay. That way in the HTML page the data is not shown.
Any tips?