title: Cannot read property 'post' of undefined - Angular 2
body: <p>Below is the code snippet from my component file</p>
  
  <pre><code>import { Component,Injectable,Inject,OnInit, OnDestroy, EventEmitter,Output } from '@angular/core';
  import { Http, Response, Headers, RequestOptions } from '@angular/http';
  import 'rxjs/add/operator/map';
  import 'rxjs/add/operator/toPromise';
  import 'rxjs/add/operator/switchMap';
  ...
  @Injectable()
  export class MyComponent {
      constructor (private http: Http) { }
      saveDetails()
      {
          var response:any;
          var body       = customer_details;
          var headers    = new Headers({ 'Content-Type': 'application/json' });
          var options    = new RequestOptions({ headers: headers });
          this.http.post("/user/add-customer-details", body, options)
              .map((res:Response) =&gt; res.json()).subscribe(
                  data =&gt; { response = data},
                  err =&gt; console.error(err),
                  () =&gt; {
                      console.log(response);
                  }
          );
      }
  }
  </code></pre>
  
  <p>There is no compilation error or any other error but
  when I am calling the post method it's saying <code>Cannot read property 'post' of undefined</code> so I tried <code>console.log(this.http);</code> right before the post method call, then its showing <code>undefined</code> in the browser console, I tried all the possible solutions but unable to understand why it's not working, please help...</p>
  
  <p>thanks in advance!!!</p>