I have been hours trying to understand why I don't get the value of a variable, outside an Angular.js function. First I get the value from a Firebase database, here is my reference :
var refspaedtServ = new Firebase(FBURLSPA + $routeParams.id);
$scope.spaedServ = $firebaseObject(refspaedtServ);
Then I have the function:
///// IMAGE REFERENCE ////
var lafoto = '';
refspaedtServ.on("value", function(rootSnapshot) {
lafoto = rootSnapshot.val().foto;
console.log("Inside image ", lafoto)
});
As you can see, I define my variable 'lafoto' as global With the console.log Inside image, I can see the value is correct
But when I try to get the value of "lafoto" variable, outside the function, I'm getting "undefined", I mean no value.
console.log("Outside Image ", lafoto)
It seems silly, but I'm reaching madness for that. Can anybody give me a hint please?
Regards, Victor