我正在尝试使用 Ionic 离子烤面包。我在他们的网站上找到了这个示例:https ://ionicframework.com/docs/api/toast
现在我的问题是:上面添加的任何按钮的“处理程序”回调都不会被调用,并且不会出现日志。我在 Android 设备和 MacOS 浏览器 Safari 上尝试了此代码,两者都显示相同的问题。
我尝试使用 toast.onDidDismiss().then(()=>{ console.log('Closed'); }) 但这没有帮助,因为我计划添加多个按钮并且我想区分哪个按钮被点击。
代码:
async presentToastWithOptions() {
const toast = await this.toastController.create({
header: 'Toast header',
message: 'Click to Close',
position: 'top',
buttons: [
{
side: 'start',
icon: 'star',
text: 'Favorite',
handler: () => {
console.log('this log should appear when this icon is clicked.');
}
}, {
text: 'Done',
role: 'cancel',
handler: () => {
console.log('This log should appear when I click done.');
} …Run Code Online (Sandbox Code Playgroud)