Hello I try to make a post for a login and I do not send the data, this is the code .. IONIC
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
import { URL_SERVICES } from '../../config/url.services';
import { AlertController } from 'ionic-angular';
@Injectable()
export class UsersProvider {
token:string;
id_user:string;
constructor(public http: Http,
private alertCtrl: AlertController) {
console.log('Hello UsersProvider Provider');
}
ingresar( email:string, password:string){
console.log("usersP ",email);
console.log("usersP ", password);
let data = new URLSearchParams();
data.append("email", email);
data.append("password", password);
let url = URL_SERVICES + "login";
return this.http.post( url, data )
.map( resp => {
let data_resp = resp.json();
console.log( data_resp );
if( data_resp.err ){
this.alertCtrl.create({
title: 'Error al iniciar',
subTitle: data_resp.message,
buttons: ['OK']
}).present();
}else{
this.token = data_resp.token;
this.id_user = data_resp.id_user;
//GUARDAR STORAGE
}
});
}
}
the url.config file
export const URL_SERVICES = "http://localhost/appWC/index.php/";
the login.ts
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
import { URL_SERVICES } from '../../config/url.services';
import { AlertController } from 'ionic-angular';
@Injectable()
export class UsersProvider {
token:string;
id_user:string;
constructor(public http: Http,
private alertCtrl: AlertController) {
console.log('Hello UsersProvider Provider');
}
ingresar( email:string, password:string){
console.log("usersP ",email);
console.log("usersP ", password);
let data = new URLSearchParams();
data.append("email", email);
data.append("password", password);
let url = URL_SERVICES + "login";
return this.http.post( url, data )
.map( resp => {
let data_resp = resp.json();
console.log( data_resp );
if( data_resp.err ){
this.alertCtrl.create({
title: 'Error al iniciar',
subTitle: data_resp.message,
buttons: ['OK']
}).present();
}else{
this.token = data_resp.token;
this.id_user = data_resp.id_user;
//GUARDAR STORAGE
}
});
}
}
the login.html
<ion-item>
<ion-label fixed>Correo </ion-label>
<ion-input type="email" [(ngModel)]="email"></ion-input>
</ion-item>
<ion-item>
<ion-label fixed>Contraseña </ion-label>
<ion-input type="password" [(ngModel)]="password"></ion-input>
</ion-item>