Skip to content Skip to sidebar Skip to footer

Firebase Data Returning An Undefined Value Even Though It Has Content

Coming from my recent question in this site (before I resort to the 'Promise' technology), I came up an idea of storing the variable in the firebase database instead of making it a

Solution 1:

The correct way would be:

keyRef.on('value', function(data){
 //  alert(data.val().currentTailor); see the difference console.log('currentTailor ==>', data.val().currentTailor);
});

alert() in javascript is not recommended as it freezes your page. Use console instead. This way you can see your logs in browser's console (in chrome press Ctrl+Shift+J)

Firebase's on() method returns the callback function . To get the data object, you have to use val() method on that return value. Then you can get any value using corresponding key.

 keyRef.on('value', function(data){
// here data is callback function
});

keyRef.on('value', function(data){
//data.val() returns the data in object form
});
 keyRef.on('value', function(data){
 // data.val().currentTailor to access currentTailor attribute
 });

You can console each of them to see what is the return values.

Post a Comment for "Firebase Data Returning An Undefined Value Even Though It Has Content"