title: Angular2 component's "this" is undefined when executing callback function
body: <p>I have a component which calls a service to fetch data from a RESTful endpoint. This service needs to be given a callback function to execute after fetching said data.</p>
  
  <p>The issue is when I try use the callback function to append the data to the existing data in a component's variable, I get a <code>EXCEPTION: TypeError: Cannot read property 'messages' of undefined</code>. Why is <code>this</code> undefined?</p>
  
  <p>TypeScript version: Version 1.8.10</p>
  
  <p>Controller code:</p>
  
  <pre><code>import {Component} from '@angular/core'
  import {ApiService} from '...'
  
  @Component({
      ...
  })
  export class MainComponent {
  
      private messages: Array&lt;any&gt;;
  
      constructor(private apiService: ApiService){}
  
      getMessages(){
          this.apiService.getMessages(gotMessages);
      }
  
      gotMessages(messagesFromApi){
          messagesFromApi.forEach((m) =&gt; {
              this.messages.push(m) // EXCEPTION: TypeError: Cannot read property 'messages' of undefined
          })
      }
  }
  </code></pre>