Hey there!
I’m am developing an application for my brother and I need to contact a remote server. For this, I’d like to use the native http plugin. Unfortunately, whatever I tried to make it work… didn’t work.
As you can see in the title, I get an error message in ionic view (“plugin_not_installed”).
First things first : (I’m developing with VS Code)
ordova CLI: 6.5.0 Ionic Framework Version: 2.3.0 Ionic CLI Version: 2.2.2 Ionic App Lib Version: 2.2.1 Ionic App Scripts Version: 1.1.4 ios-deploy version: Not installed ios-sim version: Not installed OS: Windows 10 Node Version: v6.10.1 Xcode version: Not installed
I’ve tried to recreate a new empty project with only the not-working code in it, and still not working.
Step I’ve followed:
- ionic plugin add cordova-plugin-http
- npm install --save @ionic-native/http
- Send to ionic view and test → No crash (Would have been surprised)
- Add HTTP in the app.module
import { HTTP } from ‘@ionic-native/http’;
…
providers: [
StatusBar,
SplashScreen,
HTTP,
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
- Send to ionic view and test → No crash
- Import HTTP and try to make a simple call in controller
import { Component } from ‘@angular/core’;
import { NavController } from ‘ionic-angular’;
import { HTTP } from ‘@ionic-native/http’;
@Component({
selector: ‘page-about’,
templateUrl: ‘about.html’
})
export class AboutPage {
private url: string = ‘https://myawesomeurl.com’;
private token: string = ‘myGr34tT0k3n’;
constructor(public navCtrl: NavController, public http: HTTP) {
this.getLastAttendance(‘NotMyBrothersName’, this.onLastAttendanceReceived);
}
onLastAttendanceReceived(data: any): void {
alert(data);
}
getLastAttendance(employee: string, callback: Function) : void {
let body = {token: this.token, employee : employee};
this.http.post(this.url + ‘attendances/last’, body, {})
.then(response => { if (response.status == 200) { callback(response.data); } else { alert('Type de retour bizarre : ' + response.status); } }) .catch(error => { alert('Une erreur s\'est produite : ' + error); });
}
}
- Send to ionic view and test → CRASH : Plugin_not_installed
EDIT: It’s not a crash, it’s an alert and then the application works, but not the http call
Can anyone help me ? Thanks you