Am trying to create a login page
login.html
<form (ngSubmit) = "signIn()" novalidate>
<ion-list no-line>
<ion-item>
<ion-label floating>Email</ion-label>
<ion-input [(ngModel)] ="loginData.email" name="email" type="text" ></ion-input>
</ion-item>
<ion-item>
<ion-label floating>Password</ion-label>
<ion-input [(ngModel)]="loginData.password" name="password" type="password" ></ion-input>
</ion-item>
</ion-list>
<button ion-button block outline color="primary" type="submit">Sign In </button>
</form>
login.ts
export class Login {
loginResponse:any;
loginData = {"email":"","password":""};
constructor(public navCtrl: NavController, public navParams: NavParams,public apiService: ApiService) {
}
signIn() {
this.apiService.postData(this.loginData,'login').then((result) => {
this.loginResponse = result;
console.log(this.loginResponse);
// this.navCtrl.push(HomePage);
}, (err) => {
// Error message
});
}
}
And finaly my provider
postData(data,key) {
console.log('in api');
console.log(data);
return new Promise((resolve,reject) => {
let headers = new Headers();
this.http.post(baseUrl+key,JSON.stringify(data),{headers:headers}).subscribe(res => {
resolve(res.json());
},(err) => {
reject(err);
});
});
}
This is the format am getting in my api file and it is causing errors
Object {email: “emil@gmail.com”, password: “test”}
Note that the same method actually worked for registration form