我如何捕获Ionic 4中AlertController返回的数据?

问题描述 投票:0回答:1

我有AlertService,它调用AlertController,而alertController具有此方法,

async presentAlertPrompt() {
    const alert = await this._alertController.create({
      cssClass: 'my-custom-class',
      header: 'Add Comment!',
      inputs: [
        {
          name: 'comment',
          type: 'textarea',
          placeholder: 'Comment'
        }
      ],
      buttons: [
        {
          text: 'Cancel',
          role: 'cancel',
          cssClass: 'secondary',
          handler: () => {
            console.log('Confirm Cancel');
          }
        }, {
          text: 'Ok',
          handler: (alerData) => {
            return alertData
          }
        }
      ]
    });

    await alert.present();
  }

并且一旦我在另一个组件中调用此方法,

 this._alert.presentAlertPrompt().then((data) => {
      console.log('Alert respone',data)
    })

[alertData是空的,我在这里做错了吗?

ionic-framework ionic4
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.