Hello all,
I need to update a label when the firebase has changed...
Maybe someone will already use this and have an example? I cannot get it to work.
Thank you very much!
I have make this webpage from an online video but I cannot get it working. Pleaseif someone have an example really apreciated.
Thank you! I really don't know how to implement this.
<!DOCTYPE html>
<html>
<meta name=“viewport” content=“width=device-width, initial-scale=1.0”>
<meta charset="utf-8">
<head>
<title>DataChanged</title>
<script src="https://gstatic.com/firebase.js/live/3.1/firebase.js></script>
</head>
<body>
<pre id="object"></pre>
<script >
(function() {
// initialize Firebase
const config = {
apiKey: "xxxxxxxxxxx",
authDomain: "yyyyyyyy",
databaseURL: "https://default-rtdb.firebaseio.com/",
storageBucket: "zzzzzzzzzzzz",
};
firebase.initializeApp(config);
//Get elements
const pre0bject = document.getElementById('object');
//Create references
const dbRef0bject = firebase.database().ref().child('object');
//Sync object changes
dbRef0bject.on('value', snap => {
pre0bject.innerText = JSON.stringify(snap.val(), null, 3);
});
}());
</script>
</body>
</html>