title: angular2 firebase realtime updating not working
body: <p>I have simple app that inserts new record to Firebase and below the input field it simply lists last 10 items in database.</p>
  
  <p><strong>PROBLEM:</strong></p>
  
  <ol>
  <li>I need to start inputing someting to input field or to click on "update" for data from Firebase to appear in my listing. It seems that data comes in after the processing by angular has been already done, causing it now to show the list initialy. I tried adding "| async" to ngFor, but does not work and causes errors in console. Everything is working good, just need to load and show the data onload, without me inputing a keystroke in input or clicking to update button.</li>
  <li>when I open two tabs with same app, they do not update realtime as I supposed they would once I start inputing data zig-zag from one tab to another, I only appears in the tab in which I inserted the data.</li>
  </ol>
  
  <hr>
  
  <pre class="lang-ts prettyprint-override"><code>import {Component,enableProdMode} from 'angular2/core'; enableProdMode();
  import {FirebaseService} from 'firebase-angular2/core';
  var myFirebaseRef = new Firebase("https://xxx.firebaseio.com/messages");
  
  @Component({
      selector: 'my-app',
      template: `
          &lt;input type=text [(ngModel)]="newmsg" #newmsgref (keyup.enter)="updateHello(newmsgref)"&gt;
          &lt;button (click)="updateHello(newmsgref)"&gt;Update&lt;/button&gt;
          &lt;ul&gt;
              &lt;li *ngFor="#item of items"&gt;
                {{item}}
              &lt;/li&gt;
          &lt;/ul&gt;
      `
  })
  export class AppComponent {
      newmsg:string;
      items:Array&lt;string&gt;=[];
  
      constructor() {
          myFirebaseRef.limitToLast(10).on('child_added', (childSnapshot, prevChildKey) =&gt; {
              childSnapshot.forEach((records) =&gt; {
                this.items.push(records.val());
              });
          });
      }
  
      updateHello(r){
          myFirebaseRef.push({
              title: this.newmsg
          });
          this.newmsg="";
          r.focus();
      }
  }
  </code></pre>
  
  <p><strong>SOLUTION #1 WITH NGZONE MANUAL UPDATE</strong> WHICH WORKED (thanks to: Günter Zöchbauer)
  Since the definition was outside the A2, the use of NgZone is really easy and corrected the problem. Thanks Günter ;)  </p>
  
  <pre class="lang-ts prettyprint-override"><code>import {Component,enableProdMode,NgZone} from 'angular2/core'; enableProdMode();
  import {FirebaseService} from 'firebase-angular2/core';
  var myFirebaseRef = new Firebase("https://xxx.firebaseio.com/messages");
  
  @Component({
      selector: 'my-app',
      template: `
          &lt;input type=text [(ngModel)]="newmsg" #newmsgref (keyup.enter)="updateHello(newmsgref)"&gt;
          &lt;button (click)="updateHello(newmsgref)"&gt;Update&lt;/button&gt;
          &lt;ul&gt;
              &lt;li *ngFor="#item of items"&gt;
                {{item}}
              &lt;/li&gt;
          &lt;/ul&gt; 
      `
  })
  export class AppComponent {
      newmsg:string;
      items:Array&lt;string&gt;=[];
  
      constructor(private zone: NgZone) {
          myFirebaseRef.limitToLast(10).on('child_added', (childSnapshot, prevChildKey) =&gt; {
              zone.run(() =&gt; {
                  childSnapshot.forEach((records) =&gt; {
                      this.items.push(records.val());
                  });
              });
          });
      }
  
      updateHello(r){
          myFirebaseRef.push({
              title: this.newmsg
          });
          this.newmsg="";
          r.focus();
      }
  }
  </code></pre>
  
  <p><strong>SOLUTION #2 AUTOMATIC A2 UPDATING</strong> WHICH WORKED (thanks to: Thierry)
  I simply put the definition inside the class of angular2, not outside, and everything started working as I assumed initialy. Thank you Thierry for the insight ;).</p>
  
  <pre class="lang-ts prettyprint-override"><code>import {Component,enableProdMode} from 'angular2/core'; enableProdMode();
  import {FirebaseService} from 'firebase-angular2/core';
  
  @Component({
      selector: 'my-app',
      template: `
          &lt;input type=text [(ngModel)]="newmsg" #newmsgref (keyup.enter)="updateHello(newmsgref)"&gt;
          &lt;button (click)="updateHello(newmsgref)"&gt;Update&lt;/button&gt;
          &lt;ul&gt;
              &lt;li *ngFor="#item of items"&gt;
                {{item}}
              &lt;/li&gt;
          &lt;/ul&gt;
      `
  })
  export class AppComponent {
      newmsg:string;
      items:Array&lt;string&gt;=[];
      myFirebaseRef = new Firebase("https://xxx.firebaseio.com/messages");
  
      constructor() {
          this.myFirebaseRef.limitToLast(10).on('child_added', (childSnapshot, prevChildKey) =&gt; {
              childSnapshot.forEach((records) =&gt; {
                  this.items.push(records.val());
              });
          });
      }
  
      updateHello(r){
          this.myFirebaseRef.push({
              title: this.newmsg
          });
          this.newmsg="";
          r.focus();
      }
  }
  </code></pre>