Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Firebase I want to console log my firebase data

Simple question I hope you good people can help me with.

I'm using Firebase and I can display my firebase data on the page using:

var dbRef = firebase.database().ref().child('jumbotron/header');
dbRef.on('value', snap => container.innerText = snap.val());

But when I try to: console.log(dbRef) It displays as an object. I think this is because the reference is a URL. How can I console.log or print my firebase data as a string and eventually place it on my page using vanilla javascript. I can't find the solution in the FB documentation and there aren't any tutorials on the Google FB.

Any help is much appreciated. Thanks, All

like image 406
Moe-Joe Avatar asked Jan 06 '23 17:01

Moe-Joe


1 Answers

As the name implies dbRef is a reference to the data, it is not the data itself.

When you attach a listener to the reference with on(), you will get a snapshot of the data at that location. You can get the value from this snapshot and print it:

var dbRef = firebase.database().ref().child('jumbotron/header');
dbRef.on('value', snapshot => {
  console.log(snapshot.val());
});
like image 56
Frank van Puffelen Avatar answered Jan 08 '23 08:01

Frank van Puffelen