1

我已将以下代码从 Ionic 3 迁移到 Ionic 5

   const alert = await this.alertCtrl.create({
      subHeader: "About" + " <b>" + this.user.name + "</b>",
      message: "Test Messgae",
      buttons: [
        {
          text: 'Close',
          role: 'cancel',
          handler: () => {
          }
        }
      ]
    });
    await alert.present();

在 Ionic 3 中,用户名以粗体显示,但在 Ionic 5 中,HTML 标签不起作用,< b > 标签显示为文本。请建议我如何在 IONIC 5 中设置警报中的文本样式。

4

1 回答 1

0

subHeader可以使用自定义 CSS 类加粗。在这个例子中是alertCustomClass

在此处输入图像描述

主页.ts

 async presentAlertConfirm() {
    const alert = await this.alertController.create({
      header: 'About ' + this.test,
      subHeader: this.test,
      message: 'About ' + '<strong>' + this.test + '</strong>',
      cssClass: 'alertCustomClass',
      buttons: [
        {
          text: 'Cancel',
          role: 'cancel',
          cssClass: 'secondary',
          handler: (blah) => {
            console.log('Confirm Cancel: blah');
          }
        }, {
          text: 'Okay',
          handler: () => {
            console.log('Confirm Okay');
          }
        }
      ]
    });

    await alert.present();
  }

全局.scss

.alertCustomClass {
      .alert-sub-title {
          font-weight: bold;
      }
 }

此外,您可以像这样message使用粗体:<strong>

  async presentAlertConfirm() {
    const alert = await this.alertController.create({
      header: 'Confirm!',
      message: 'About ' + '<strong>' + this.user.name + '</strong>',
      buttons: [
        {
          text: 'Cancel',
          role: 'cancel',
          cssClass: 'secondary',
          handler: (blah) => {
            console.log('Confirm Cancel: blah');
          }
        }, {
          text: 'Okay',
          handler: () => {
            console.log('Confirm Okay');
          }
        }
      ]
    });

    await alert.present();
  }

headerfont-weight:500;默认为粗体 ( )。

...
   header: 'About ' + this.user.name,
   message: ...,
   buttons: ,,,.
...
于 2020-04-09T21:17:26.823 回答