使用javascript开始使用firebase

getting started with firebase with javascript

本文关键字:firebase 开始 javascript 使用      更新时间:2023-09-26

我刚刚开始使用firebase和javascript html为我的应用程序制作一个网站。

我所要做的就是从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>

我错过了什么吗?我是新来的,所以可能有一小步我错过了。

Try with:

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