Struggling to implement API calls in Ionic for the purpose of signing in. Unsure of the correct method to make the call.
Previous attempts to call the API have been unsuccessful.
signin.ts
import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import { HTTP } from '@ionic-native/http'
@Component({
selector: 'page-sign-in',
templateUrl: 'sign-in.html',
})
export class SignInPage {
private signinUrl:"*someurl*";
email="";
password="";
constructor(public navCtrl: NavController, public navParams: NavParams,
private http:HTTP) {
}
ionViewDidLoad() {
console.log('ionViewDidLoad SignInPage');
}
signinClick(){
this.callSignInApi(this.email,this.password);
}
callSignInApi(email:string,password:string){
console.log('api email',email);
console.log('api pass',password);
let urlSearchParams = new URLSearchParams();
urlSearchParams.append('username', email);
urlSearchParams.append('password', password);
this.http.post(this.signinUrl,urlSearchParams.toString(),{})
.then(data => {
console.log("data status",data.status);
console.log("data data",data.data); // data received by server
console.log("data headers",data.headers);
})
.catch(error => {
console.error("catching error",error);
console.log("error status",error.status);
console.log("error error",error.error); // error message as string
console.log("error headers",error.headers);
});
}
}
Encountering an error when trying to call the API on button click, with the error being null. Unsure of the specific error message or how to correctly pass parameters.