0

// Initialize Firebase var config = { apiKey: "AIzaSyBz13eirmEOGD1uXOZwf6tKGnEsjfwsUFo", authDomain: "platformtechproject.firebaseapp.com", databaseURL: "https://platformtechproject.firebaseio.com", projectId: "platformtechproject", storageBucket: "platformtechproject.appspot.com", messagingSenderId: "1065758005439" }; firebase.initializeApp(config); var database = firebase.database(); var msgRef = firebase.database().ref('survey'); //console.log(firebase); var msgRef = firebase().ref('survey'); msgRef.on('value',gotData,errData); 

I continue getting this error [Uncaught TypeError: firebase is not a function] as i am trying to read firebase data to web. Chrome console error

1

2 Answers 2

0

here's how your code must be:

<script src="https://www.gstatic.com/firebasejs/4.8.0/firebase.js"></script> <script> // Initialize Firebase var config = { apiKey: "AIzaSyBz13eirmEOGD1uXOZwf6tKGnEsjfwsUFo", authDomain: "platformtechproject.firebaseapp.com", databaseURL: "https://platformtechproject.firebaseio.com", projectId: "platformtechproject", storageBucket: "platformtechproject.appspot.com", messagingSenderId: "1065758005439" }; firebase.initializeApp(config); var database = firebase.database(); var msgRef = database.ref('survey'); msgRef.on("child_added",function(snapshot) { var changedPost = snapshot.val(); console.log(changedPost) }); </script> 

The code above works as you expect: enter image description here

Note that msgRef listens on these predefined "events".

Details here: Read Event Types

Regards

Sign up to request clarification or add additional context in comments.

Comments

0

Change this:

 var database = firebase.database(); var msgRef = firebase.database().ref('survey'); //console.log(firebase); var msgRef = firebase().ref('survey'); msgRef.on('value',gotData,errData); 

to this:

 var database = firebase.database(); var msgRef = database.ref('survey'); msgRef.on('value', function(snapshot) { //retrieve data }); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.