Q:

Cannot read property 'post' of undefined - Angular 2

Below is the code snippet from my component file
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) => res.json()).subscribe(
                data => { response = data},
                err => console.error(err),
                () => {
                    console.log(response);
                }
        );
    }
}

There is no compilation error or any other error but
when I am calling the post method it's saying Cannot read property 'post' of undefined so I tried console.log(this.http); right before the post method call, then its showing undefined in the browser console, I tried all the possible solutions but unable to understand why it's not working, please help...
thanks in advance!!!

A:

After spending a few hours in scratching my head and reading all the possible articles, answers, documentation and possibly everything available on the Internet, finally I found the solution.
I have just changed my constructor from
constructor (private http: Http) { }

To
constructor (@Inject(Http) private http:Http) { }

Though @Inject is an Experimental decorator, It's working
Thank you everyone for helping me...

