Property 'http' does not exist on type 'Component', Angular 2 Property 'http' does not exist on type 'Component', Angular 2 typescript typescript

Property 'http' does not exist on type 'Component', Angular 2


Just add private to make your Http instance available to your entire component:

constructor(private http: Http)


It has something to do with your http variable try this

In your component.ts

constructor(http: Http) {    http.get('api/departments')      .map((res: Response) => res.json())      .subscribe((departments: Array<any>) => this.departments = departments);  }

You could try

constructor(private http: Http) {    http.get('api/departments')      .map((res: Response) => res.json())      .subscribe((departments: Array<any>) => this.departments = departments);  }


You have to export the Http module in the module in the exports declaration.

@NgModule({  imports: [CommonModule, RouterModule, ReactiveFormsModule, ],  declarations: [ ErrorMessagesComponent, FoodDashboardComponent ],  exports: [ CommonModule, ReactiveFormsModule, HttpModule, RouterModule, ]})