I am making an app with ionic 3 and I want to use the HTTP module. I used the official documentation of the Ionic framework.
Link: https://ionicframework.com/docs/native/http/
I did these commands:
$ ionic cordova plugin add cordova-plugin-advanced-http
$ npm install --save @ionic-native/http
So far so good. Then I added this module into my app.module.ts file and the code looks like this:
import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { SplashScreen } from '@ionic-native/splash-screen';
import { StatusBar } from '@ionic-native/status-bar';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { ResultstatsPage } from '../pages/resultstats/resultstats';
import { HTTP } from '@ionic-native/http';
@NgModule({
declarations: [
MyApp,
HomePage,
ResultstatsPage
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp),
HTTP
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage,
ResultstatsPage
],
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
})
export class AppModule {}
I have made an function with the HTTP like this:
getStats(){
this.http.get(this.url, {}, this.apikey)
.then(data => {
console.log(data.status);
console.log(data.data); // data received by server
console.log(data.headers);
})
.catch(error => {
console.log(error.status);
console.log(error.error); // error message as string
console.log(error.headers);
});
}
When I run the app with ionic serve I get a error (see screenshot)
I have tried several solutions but it didn't solve the issue. Can someone point me in the right direction?
