I\'m trying to create a simple program that takes name, mobile number and email address from user and then puts the data on Firebase Realtime Database.
There are 3 i
var reference = db.ref('/test/');
reference.on('value', function(snapshot) {
snapshot.forEach(function(userSnapshot){
console.log(userSnapshot.val().url)
document.getElementById('gmap').href = userSnapshot.val().location;
document.getElementById('gimg2').src = userSnapshot.val().url;
document.getElementById('name').innerHTML = userSnapshot.val().uid;
I was facing the same issue. I wanted to read the data from the firebase realtime database and print the same on the web.
The data I am reading is in the test document.
Use the on() function to take the snapshot of it.
Firebase provides you with a foreach loop to iterate over the data in the test document.
The variable userSnapshot reads the value while looping. The variables location, url, uid are the keys in the test document.
document.getElementById('gmap').href
document.getElementById('gimg2').src
document.getElementById('name').innerHTML
are the DOM element to print the data on the web
See location
I hope this helps someone.