title: Typescript class variable return undefined inside Firebase function
body: <p>I come from a python/golang background and now I diving into ionic2.
  I wonder if I doing something stupid, or there is an issue, which at my current knowledge of the stack, I cannot tell where its from. Maybe I only need a way to reference the outer scope of this function. Well, I am looping through my user collection and get the data printed to the console like this with the code base down below the question:</p>
  
  <pre><code>page1.ts:81 key -KFoJ-oF-ll04zmxJZiL
  page1.ts:88 data Object {email: "sdcsd@gmail.com", username: "cesscd"}
  page1.ts:89 user UserAllowed {email: "sdcsd@gmail.com", username: "cesscd"}
  </code></pre>
  
  <p>But as soon as I try to push a new user to the allowed user array I get  this error;</p>
  
  <pre><code>FIREBASE WARNING: Exception was thrown by user callback. TypeError: Cannot read property 'alloweduser' of undefined
      at http://localhost:8100/build/js/app.bundle.js:98:21
      at https://cdn.firebase.com/js/client/2.4.1/firebase.js:200:356
      at Kc.h.ka (https://cdn.firebase.com/js/client/2.4.1/firebase.js:35:275)
      at Kc.h.ka (https://cdn.firebase.com/js/client/2.4.1/firebase.js:35:268)
      at Kc.h.ka (https://cdn.firebase.com/js/client/2.4.1/firebase.js:35:268)
      at Kc.h.ka (https://cdn.firebase.com/js/client/2.4.1/firebase.js:35:268)
      at Ec.h.ka (https://cdn.firebase.com/js/client/2.4.1/firebase.js:32:465)
      at fe.h.R (https://cdn.firebase.com/js/client/2.4.1/firebase.js:83:379)
      at W.forEach (https://cdn.firebase.com/js/client/2.4.1/firebase.js:200:326)
      at http://localhost:8100/build/js/app.bundle.js:88:22 
  </code></pre>
  
  <h2>Code base</h2>
  
  <pre><code>export class Page1 {
      reponse:string;
      firebaseUrl:string;
      userRef:Firebase;
      alloweduser: UserAllowed[];
      constructor() {
          this.firebaseUrl = "https://fghghgf-hefghgfhat-gh.firebaseio.com/web/data/";
          this.userRef = new Firebase(this.firebaseUrl).child("users");
      }
  
          ngOnInit(){
          this.alloweduser=[];
          this.userRef.once("value", function(snapshot) {
              // The callback function will get called twice, once for "fred" and once for "barney"
              snapshot.forEach(function(childSnapshot) {
                  // key will be "fred" the first time and "barney" the second time
                  var key = childSnapshot.key();
                  console.log("key",key);
                  // childData will be the actual contents of the child
                  var childData = childSnapshot.val();
                  var user = new UserAllowed("","");
                  var user = new UserAllowed(childData.username,childData.email);
                  console.log("data",childData);
                  console.log("user",user);
                  //Why this.alloweduser get undefined inside this function?
                  this.alloweduser.push(user);
              });
          });
      }
  
      }
  
  
      // TypeScript
  class UserAllowed {
      // Property (public by default)
      email: string;
      username: string;
      // Constructor
      // (accepts a value so you can initialize engine)
      constructor(username:string, email: string) {
          this.email = email;
          this.username = username;
      }
  }
  </code></pre>