首页 > 解决方案 > 异步和等待的目的?

问题描述

我曾尝试研究 async 和 await 的使用,但我不明白。用外行的话来说它有什么用?我们可以在哪里使用它?

就像在这个例子中一样,什么是异步或函数试图做什么。

异步和等待的示例

   resetPassword(email: string) {
this.angularFire.sendPasswordResetEmail(email).then(async () => {
  let alert = await this.alertCtrl.create({
    header: 'Reset Password',
    message: 'Password reset email sent! Check your inbox.',
    buttons: [{
      text: "OK",
      handler: () => {
        this.navCtrl.pop();
      }
    }]
  })
  await alert.present();
}).catch(async () => {
  let alert = await this.alertCtrl.create({
    header: 'Alert',
    message: "Email or account does not exist. Please try again with a valid email or account!",
    buttons: [{
      text: "OK",
      handler: () => { }
    }]
  })
  await alert.present();
});

}

标签: ionic-frameworkasync-awaitionic5

解决方案


推荐阅读