我希望用户可以选择更改他的密码。因此,首先他有第一个警报,在那里他有一个输入他的旧pw,并有一个重复它。那么新的警报应该紧跟其后,他可以输入他的新密码两次。但此警报从未被调用过。我想知道错误是否出在if语句中,但到目前为止,我认为我已经正确地完成了所有工作。
page.ts
public password1 = '';
public password2 = '';
constructor(public alertController: AlertController) {}
async changePw() {
const alert = await this.alertController.create({
header: 'Change your Password?',
message: 'Type in your old password?',
inputs: [
{
name: 'password1',
placeholder: 'Old password',
type: 'password'
},
{
name: 'password2',
placeholder: 'Repeat old password',
type: 'password'
}
],
buttons: [
{
text: 'Cancel',
role: 'cancel',
handler: data => {
console.log('Cancel clicked');
}
},
{
text: 'Submit',
handler: async data => {
if (this.password1 === this.password2 && this.password2 !== '') {
const alert2 = await this.alertController.create({
header: 'Change your Password?',
message: 'Type in your old password?',
inputs: [
{
name: 'password3',
placeholder: 'New password',
type: 'password'
},
{
name: 'password4',
placeholder: 'Repeat new password',
type: 'password'
}
]
});
await alert2.present();
} else {
// invalid pw
return false;
}
}
}
]
});
await alert.present();
}发布于 2019-08-14 19:50:09
我不确定这是你的全部代码,还是你只是在寻找逻辑处理。
但我认为主要问题是您没有使用从警报控制器返回的数据。因此,请检查提交按钮处理程序上的数据使用情况。在本例中,使用您为输入字段指定的名称data.password1,您可以测试输入。
所以在你的代码中,password2 !== ""总是假的,因为你没有设置它。
但是,您仍然必须将旧密码合并到此函数中。
const alert1 = await this.aAlertController.create({
header: 'Change your Password?',
message: 'Type in your old password?',
inputs: [
{
name: 'password1',
placeholder: 'Old password',
type: 'password'
},
{
name: 'password2',
placeholder: 'Repeat old password',
type: 'password'
}
],
buttons: [
{
text: 'Cancel',
role: 'cancel',
handler: data => {
console.log('Cancel clicked');
}
},
{
text: 'Submit',
handler: data => {
if (data.password1 === data.password2 && data.password2 !== '') {
const alert2 = this.aAlertController.create({
header: 'Change your Password?',
message: 'Type in your old password?',
inputs: [
{
name: 'password3',
placeholder: 'New password',
type: 'password'
},
{
name: 'password4',
placeholder: 'Repeat new password',
type: 'password'
}
]
});
alert2.present();
} else {
// invalid pw
return false;
}
}
}
]
});
await alert1.present();
}希望这能有所帮助。
https://stackoverflow.com/questions/57479221
复制相似问题