title: TypeError: Cannot read property 'http' of undefined angular 2
body: <p>After successfully implementing the gapi client in my Angular 2 app, I am now encounter an issue where my http object is undefined and I am not sure why.</p>
  
  <p>Below is the code:
      constructor(private http: Http )  {}</p>
  
  <pre><code>initGmailApi() {
  
  gapi.auth2.getAuthInstance().grantOfflineAccess().then(function(resp) {
      console.log(resp);
      const auth_code = resp.code;
  
      const body = {'AuthCode': auth_code};
      const headers = new Headers();
      headers.append('Content-Type', 'application/json');
      this.http.post('http://localhost:8080/startgmail', body,  headers).subscribe(
      (Response) =&gt; {
          console.log(Response);
      }
      );
  });
  }
  </code></pre>
  
  <p>Basically what I am doing is requesting a permission from the user to access his gmail account and when I have a response I would like to pass some data received to my backend server.</p>
  
  <p>If I am using this.http outside the "then" clause then the http method works fine however this create another issue where the "auth_code" value is not recognized.</p>
  
  <p>What am I missing here? </p>