Referencing Firebase Database With A Variable And String Concatenation
As you can see below i'm trying to read a list of data from the database and then loop over the result, in javascript. The function runs whenever i open/refresh the page: firebase.
Solution 1:
It is extremely unlikely that the problem is in the string concatenation itself. It is much more likely that uid
simple doesn't have a value yet when you start reading from the database.
To make sure the uid
is available, put the reading of the data into the auth state listener like this:
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
uid = user.uid;
console.log("uid="+uid);
firebase.database().ref("Users/" + uid + "/rooms").on("value", function(snapshot) {
snapshot.forEach(function(e) {
var element = e.val();
var roomId = element.Id;
console.log("roodId="+roomId);
});
});
}
})
Post a Comment for "Referencing Firebase Database With A Variable And String Concatenation"