【问题标题】:Ionic 5 toastController doesn't show "close" buttonIonic 5 toastController 不显示“关闭”按钮
【发布时间】:2026-01-03 04:30:01
【问题描述】:

我从 Ionic 4 迁移到 Ionic 5,发现我的 toastControllers 没有显示“关闭”按钮,即使我使用 showCloseButton: true

设置了 ToastOptions 属性

【问题讨论】:

    标签: ionic-framework ionic4 ionic5


    【解决方案1】:

    我修复了它,像这样显式添加按钮数组:

    let toast = this.toastCtrl.create({
        message: 'User was added successfully',
        showCloseButton: true,
        position: 'top',
        buttons: [
              {
                text: "close",
                handler: () => {
                  console.log('Close clicked');
                }
              }
            ]
      });
    

    【讨论】: