title: Cannot set property 'variable' of null on Firebase
body: <p>I have this code to check either the Firebase connected to the internet or not. But the problem shows that my <code>this.total_downloaded=1</code> cannot be set even I was declared before <code>construct()</code> as <code>public total_downloaded=0</code>. </p>
  
  <p><a href="https://i.stack.imgur.com/NolmH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NolmH.png" alt="enter image description here"></a></p>
  
  <p>Why does it happen like that? Shouldn't I be able to use my function or set the variable easily?</p>
  
  <p>Can someone help me? Thanks. Here's my code:</p>
  
  <pre><code>public this.total_downloaded = 0;
  //...
  var connectedRef = firebase.database().ref('/.info/connected');
  connectedRef.once("value", function(snap) {
      if (snap.val() === true) {
          firebase.database()
              .ref("last_update")
              .once('value', (snap_0) =&gt; {
                  if (data.rows.item(0).value != snap_0.val().value) {
                      this.update_hok_baghu(db);
  
                      var query_insert_last_update = "UPDATE last_update SET value =" + snap_0.val().value + "";
                      db.executeSql(query_insert_last_update, []).then(() =&gt; {
                      }, (error) =&gt; {
                          console.log("ERROR on update to last_update: " + JSON.stringify(error));
                      });
  
                  } else {
                      this.total_downloaded = 1;
                  }
              });
      } else {
          this.total_downloaded = 1;
      }
  });
  </code></pre>