No provider for Http StaticInjectorError
In order to use Http in your app you will need to add the HttpModule to your app.module.ts:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule, ErrorHandler } from '@angular/core';
import { HttpModule } from '@angular/http';
...
imports: [
BrowserModule,
HttpModule,
IonicModule.forRoot(MyApp),
IonicStorageModule.forRoot()
]
EDIT
As mentioned in the comment below, HttpModule
is deprecated
now, use import { HttpClientModule } from '@angular/common/http'
; Make sure HttpClientModule
in your imports:[]
array
Update: Angular v6+
For Apps converted from older versions (Angular v2 - v5): HttpModule is now deprecated and you need to replace it with HttpClientModule or else you will get the error too.
- In your app.module.ts replace
import { HttpModule } from '@angular/http';
with the new HttpClientModuleimport { HttpClientModule} from "@angular/common/http";
Note: Be sure to then update the modulesimports[]
array by removing the oldHttpModule
and replacing it with the newHttpClientModule
. - In any of your services that used HttpModule replace
import { Http } from '@angular/http';
with the new HttpClientimport { HttpClient } from '@angular/common/http';
Update how you handle your Http response. For example - If you have code that looks like this
http.get('people.json').subscribe((res:Response) => this.people = res.json());
The above code example will result in an error. We no longer need to parse the response, because it already comes back as JSON in the config object.
The subscription callback copies the data fields into the component's config object, which is data-bound in the component template for display.
For more information please see the - Angular HttpClientModule - Official Documentation