I've been working on developing an app using Ionic 3 and I decided to implement the HTTP module. For reference, I relied on the official documentation provided by the Ionic framework.
Documentation Link: https://ionicframework.com/docs/native/http/
To begin, I executed the following commands:
$ ionic cordova plugin add cordova-plugin-advanced-http
$ npm install --save @ionic-native/http
Progressing smoothly, I then integrated this module into my app.module.ts
file, resulting in the following code:
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],
...
In order to interact with the server using the HTTP module, I created a function 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);
})
...
});
}
However, when I attempt to run the application using 'ionic serve', I encounter an error message as shown in the screenshot below:
https://i.sstatic.net/fQJLv.png
Despite trying out various solutions, I have not been able to resolve this issue. Any guidance or suggestions on how to address this problem would be greatly appreciated.