title: angular2 service base class inheritance - why is 'this' null?
body: <p>I am attempting to use inheritance to make a universal error handler for my services, but for some reason, when it gets to the error handler itself, 'this' is always seeming to be null, and I cannot figure out why.  I can get into the error handler just fine, but I always get:</p>
  
  <blockquote>
    <p>EXCEPTION: Uncaught (in promise): TypeError: Cannot read property
    'http' of null</p>
  </blockquote>
  
  <p>Any idea what I am missing/doing wrong?  Not sure how 'this' can ever be null?</p>
  
  <p>Here is my whole base class for a service:</p>
  
  <pre><code>import { Injectable } from '@angular/core';
  import { Http } from '@angular/http';
  
  @Injectable()
  export class HttpServiceBase {
  
      constructor(public http: Http) {
          console.log('http', this.http); //just do this to prove that it is there - it is!
      }
  
      handleError(error: any): Promise&lt;any&gt; {
          console.error('Application Error', error); //this logs fine
  
          // TypeError: Cannot read property 'http' of null
          this.http.get('/Account/IsLoggedIn')
              .map(response =&gt; console.log('RESPONSE: ', response));
  
          return Promise.reject(error.message || error);
      }
  }
  </code></pre>
  
  <p>And this is my inheriting class:</p>
  
  <pre><code>import 'rxjs/add/operator/toPromise';
  import { Injectable } from '@angular/core';
  import { Headers, Http } from '@angular/http';
  import { HttpServiceBase } from './http-service.base';
  import { Hero } from './hero';
  
  @Injectable()
  export class HeroService extends HttpServiceBase {
  
      private headers = new Headers({ 'Content-Type': 'application/json' });
      private heroesUrl = 'http://localhost:57569/Home/Heroes';
  
      constructor(http: Http) { super(http); }
  
      getHeroes(): Promise&lt;Hero[]&gt; {
          console.log('getting heroes');
  
          return this.http.get(this.heroesUrl + '-force-error') //so it will error out
              .toPromise()
              .then(response =&gt; response.json() as Hero[] )
              .catch(this.handleError);
      }
  }
  </code></pre>