I want to call a function after receiving value of a variable from firebase database, and then pass that variable for further calculations but value of that variable has passed as "undefined". On setting some Timeout on calculations, do the job, but I want some accurate alternative.
I have used callback, ajax and when-then but none is working.
Below is an example, using callback-
function f2(array){
// do some task
}
var startingDates=firebase.database().ref('Center/'+$id+'/StartingDates');
var variable=[];
function f1(callback){
startingDates.on('value',function(snapshot){
variable=snapshot.val();
});
callback(variable); //variable is passed as "undefined" in f2
}
f1(f2);