Reputation: 981
I want to get a value outside of a function in firebase to use globally, but it is not working.
var ref = new Firebase("https://xxxxx.firebaseio.com/users/xxxx/roles/admin/"); // true or false
ref.once("value", function(snapshot) {
console.log("here");
console.log(snapshot.val());
var isAdmin = snapshot.val();
return isAdmin;
});
console.log(isAdmin); /// cannot get value
Upvotes: 0
Views: 175
Reputation: 8926
You cannot use isAdmin
outside, because it is not available, use it in callback
ref.once("value", function(snapshot) {
//You should wrap you code here, to use isAdmin variable
//You can do whatever with isAdmin, but you can't return it.
//It's callback that running asynchronously
console.log(isAdmin)
})
Upvotes: 1