Hey im trying to get the username from my firebase db and return it but all i get is “undefined”. why is that?
Here is my code :
test():string{
var userId = firebase.auth().currentUser.uid;
var snap;
var ref = firebase.database().ref('users/' + userId + '/username');
ref.on("value", function(snapshot) {
snap = snapshot.val();
}, function (error) {
console.log("Error: " + error.code);
});
return snap;
}