带有警报框消息IonicSafeString的事件处理程序

bcs8qyzn  于 9个月前  发布在  Ionic
关注(0)|答案(1)|浏览(70)
  • .ts*
private async openUpdatedTermsOfServiceAlert(): Promise<void> {
    const alert = await this.alertController.create({
      header: 'Updated Terms of Service',
      //issue is here
      message: 
 new IonicSafeString(`<ion-button id="terms-of-service">Clear</ion-button>`),
      buttons: [
        {
          text: 'Cancel',
          role: 'cancel',
          handler: (): void => {},
        },
        {
          text: 'Continue',
          handler: (): void => {},
        },
      ],
      mode: 'ios',
      cssClass: 'play-next',
      backdropDismiss: false,
    });

    await alert.present();
  }

你能告诉我如何添加click()事件处理程序吗?我试过很多次。但还没找到。

`new IonicSafeString(`<ion-button fill="clear">Clear</ion-button>`),`

我看到了这个反馈。但是不清楚如何使用上面的用例来实现。这里有什么帮助吗?
参考:https://github.com/ionic-team/ionic-framework/issues/25584#issuecomment-1183277927

yrdbyhpb

yrdbyhpb1#

  • Ionic Framework的首席开发人员和产品经理:Liam DeBeasi帮助我解决了这个问题。多亏了他
  • .ts*
//.... other alert box code

 await alert.present();

 alert.querySelector('#terms-of-service').addEventListener('click', () => {
      this.router.navigateByUrl('legal/terms');
      this.alertController.dismiss();
    });
  • ionic.config.json*
{
  "name": "my.Ionic",
  "innerHTMLTemplatesEnabled": true,//this is important here
  "type": "angular"
}

相关问题