New filters on the Home Feed, take a look!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

1
Getting started Why isnt the .on function showing anything in the console
Post Body

Solved : The Read and Write Rules were set to False. I thought I set them to true when I created the project. I am not sure why and how they turned to False again.

So I am just getting started with Firebase. Downloaded the CLI, init a project from a CLI and deployed it to Firebase hosting. However I can't get the .on() function to work for the database neither I can figure out how to read a value from the Database. I have been tried looking at several videos and the documentation and I have no idea whats wrong.

All the code is in the index.html. I do have an entry named object in the Database.

     try {
    let app = firebase.app();
    let features = ['auth', 'database', 'messaging', 'storage'].filter(feature => typeof app[feature] === 'function');
    document.getElementById('load').innerHTML = `Firebase SDK loaded with ${features.join(', ')}`;

    console.log("This code is working");

    //Get elements
    const preObject = document.getElementById('object');

    console.log(firebase.database());

    //Create Reference
    const dbRefObject = firebase.database().ref().child('object');

    //Sync Object
    dbRefObject.on('value', snap => console.log(snap.val()));

    firebase.database().ref("object/").on('value',function(snapshot){console.log(snapshot.val());});


} catch (e) {
  console.error(e);
  document.getElementById('load').innerHTML = 'Error loading the Firebase SDK, check the console.';
}
});

Author
Account Strength
90%
Account Age
6 years
Verified Email
Yes
Verified Flair
No
Total Karma
4,383
Link Karma
368
Comment Karma
4,015
Profile updated: 9 hours ago
Posts updated: 1 day ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
5 years ago