如果仔细查看模板,则会错误地输入第二个密码:
<ion-row>
<ion-col col-12 class="divme">
<ion-input round type="text" placeholder="Username" name="username" #username></ion-input>
</ion-col>
<ion-col col-12 class="divme">
<ion-input round type="password" placeholder="Password" name="password" #password></ion-input>
</ion-col>
</ion-row>
然后在TS代码中:
constructor(public navCtrl: NavController, public alertCtrl: AlertController,
private http: Http, public loading: LoadingController, public navParams: NavParams) {
}
ionViewAfterViewInit() {
this.username.nativeElement.value=="" ;
this.password.nativeElement.value==""
}
registerPage(){
this.navCtrl.push(RegisterPage);
}
signIn(){
//// check to confirm the username and password fields are filled
if(this.username.nativeElement.value=="" ){
let alert = this.alertCtrl.create({
title:"ATTENTION",
subTitle:"Username field is empty",
buttons: ['OK']
});
alert.present();
} else
if(this.password.nativeElement.value==""){
let alert = this.alertCtrl.create({
title:"ATTENTION",
subTitle:"Password field is empty",
buttons: ['OK']
});
alert.present();
}
else
{
var headers = new Headers();
headers.append("Accept", 'application/json');
headers.append('Content-Type', 'application/json' );
let options = new RequestOptions({ headers: headers });
let data = {
username: this.username.nativeElement.value ,
password: this.password.nativeElement.value
};
let loader = this.loading.create({
content: 'Processing, please waitâ¦',
});
loader.present().then(() => {
this.http.post('http://localhost:90/totallight/api/login.php',data,options)
.map(res => res.json())
.subscribe(res => {
console.log(res)
loader.dismiss()
if(res=="Your Login success"){
let alert = this.alertCtrl.create({
title:"CONGRATS",
subTitle:(res),
buttons: ['OK']
});
alert.present();
}else
{
let alert = this.alertCtrl.create({
title:"ERROR",
subTitle:"Your Login Username or Password is invalid",
buttons: ['OK']
});
alert.present();
}
});
});
}
}
}