首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >if-statement之后未调用新警报

if-statement之后未调用新警报
EN

Stack Overflow用户
提问于 2019-08-13 21:50:27
回答 1查看 58关注 0票数 1

我希望用户可以选择更改他的密码。因此,首先他有第一个警报,在那里他有一个输入他的旧pw,并有一个重复它。那么新的警报应该紧跟其后,他可以输入他的新密码两次。但此警报从未被调用过。我想知道错误是否出在if语句中,但到目前为止,我认为我已经正确地完成了所有工作。

page.ts

代码语言:javascript
复制
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();
  }
EN

回答 1

Stack Overflow用户

发布于 2019-08-14 19:50:09

我不确定这是你的全部代码,还是你只是在寻找逻辑处理。

但我认为主要问题是您没有使用从警报控制器返回的数据。因此,请检查提交按钮处理程序上的数据使用情况。在本例中,使用您为输入字段指定的名称data.password1,您可以测试输入。

所以在你的代码中,password2 !== ""总是假的,因为你没有设置它。

但是,您仍然必须将旧密码合并到此函数中。

代码语言:javascript
复制
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();
        }

希望这能有所帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57479221

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档