Hi All,
Since there’s no tutorial yet on the breaking changes affecting Ionic v3’s use of angular/http, I hope this will help anyone with the following errors:
HttpModule is not defined
or
Uncaught (in promise): Error: No provider for Http!
Here are the changes you need to make to use native Http in Ionic v3…
app.module.ts
import { HttpModule } from '@angular/http';
...
@NgModule({
...
imports: [
BrowserModule,
HttpModule,
IonicModule.forRoot(MyApp),
],
...
MyPage.ts
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/timeout';
...
constructor(public navCtrl: NavController, public navParams: NavParams, public http: Http) {
}
...
ETPhoneHome() {
let path = 'http://localhost:8080/foo';
let encodedPath = encodeURI(path);
let timeoutMS = 10000;
this.http.get(encodedPath)
.timeout(timeoutMS)
.map(res => res.json()).subscribe(data => {
let responseData = data;
console.log(responseData);
},
err => {
console.log('error in ETPhoneHome');
});
}
And that’s it!
Thanks,
Ryan