2016-09-09 56 views
-2

我剛剛開始使用firebase和javascript html爲我的應用程序創建網站。開始使用JavaScript的firebase

我想要做的就是從Firebase訪問任何值,並將其打印在網站上。

我跟着火力的快速入門教程和複製完全相同的代碼,他們有:https://www.youtube.com/watch?v=k1D0_wFlXgo

這裏是代碼:

<!DOCTYPE html> 

<html> 
    <head> 
    <meta charset="utf-8"> 
    <title>Javascript</title> 

    </head> 


<body> 

    <h1 id="bigOne"></h1> 
    <script src="https://www.gstatic.com/firebasejs/3.3.2/firebase.js"></script> 
    <script> 
    // Initialize Firebase 
     var config = { 
     apiKey: "AIzaSyD0C9hhfpdKEIahisG0VNInZZGjCyf5Lo0", 
     authDomain: "game-of-chats-ce897.firebaseapp.com", 
     databaseURL: "https://game-of-chats-ce897.firebaseio.com", 
     storageBucket: "game-of-chats-ce897.appspot.com", 
     }; 
     firebase.initializeApp(config); 
     var bigOne = document.getElementById('bigOne'); 
     var dbRef = firebase.database().ref().child('text'); 

     dbRef.on('value', snap => bigOne.innerText) = snap.val()) 

    </script> 
</body> 

</html> 

我這麼想嗎?我是新的,所以可能會有一小步我錯過了。

+3

您有一個額外的')'這行'dbRef.on( '價值' 的結尾,扣=> bigOne.innerText)= snap.val() )'。 – Alex

+1

但是作爲一個方面說明,我還建議你在'console.firebase.google.com'的'Databases'下檢查你的規則,以確保你實際上擁有'read' /'write'權限!對於開發,你可以將'false'改爲'true'。 – Alex

回答

0

嘗試用:

dbRef.on('value', function(snapshot) { 
    bigOne.innerText = snapshot.val(); 
});