Slava Slava - 2 months ago 8
Javascript Question

Gettting data from firebase not woks

I init my web app with firebase, then I add new data into database: {'title': 'hello world!'}. Then I try to get this data:

database.ref().child('title')
and I got strange object:
enter image description here

How to get my data?
Firebase version: 3.4.0

Answer

Firebase queries are asynchronous. Hence, you need to register a callback so that Firebase can inform you when the results are ready.

Try this:

database.ref().child('title').on('value', (snapshot) => {
    console.log(snapshot.val());
});

You may read this for more information.

Comments