创建 toast 时 showCloseButton 出错
Error with showCloseButton when creating toast
我正在学习关于 Skillshare 的 "Ionic 4 Firebase with Angular-Build PWA, Native Android, iOS" 教程。其中一项要求是创建一个 toast,在用户注册应用程序时显示,并带有一个关闭按钮。
我已按照示例进行操作,但 "showCloseButton: true" 整个语句下方有一条红色错误线。
这是我的代码:
async presentToast(message) {
const toast = await this.toastController.create({
message,
duration: 1500,
showCloseButton: true,
position: this.platform.is('desktop') ? 'top' : 'bottom'
});
toast.present();
}
这是我收到的错误消息:
(property) showCloseButton: boolean
Argument of type '{ message: any; duration: number; showCloseButton: boolean; position: "top" | "bottom"; }' is not assignable to parameter of type 'ToastOptions'.
Object literal may only specify known properties, and 'showCloseButton' does not exist in type 'ToastOptions'.ts(2345)
任何帮助将不胜感激。
Ionic4 没有用于 Toast 的关闭按钮 属性。但是您可以添加具有 'cancel'
角色的按钮,如 the documentation.
中所述
const toast = await this.toastController.create({
header: 'Toast header',
message: 'Click to Close',
position: 'top',
buttons: [
{
text: 'Done',
role: 'cancel',
handler: () => {
console.log('Cancel clicked');
}
}
]
});
toast.present();
我正在学习关于 Skillshare 的 "Ionic 4 Firebase with Angular-Build PWA, Native Android, iOS" 教程。其中一项要求是创建一个 toast,在用户注册应用程序时显示,并带有一个关闭按钮。
我已按照示例进行操作,但 "showCloseButton: true" 整个语句下方有一条红色错误线。
这是我的代码:
async presentToast(message) {
const toast = await this.toastController.create({
message,
duration: 1500,
showCloseButton: true,
position: this.platform.is('desktop') ? 'top' : 'bottom'
});
toast.present();
}
这是我收到的错误消息:
(property) showCloseButton: boolean Argument of type '{ message: any; duration: number; showCloseButton: boolean; position: "top" | "bottom"; }' is not assignable to parameter of type 'ToastOptions'.
Object literal may only specify known properties, and 'showCloseButton' does not exist in type 'ToastOptions'.ts(2345)
任何帮助将不胜感激。
Ionic4 没有用于 Toast 的关闭按钮 属性。但是您可以添加具有 'cancel'
角色的按钮,如 the documentation.
const toast = await this.toastController.create({
header: 'Toast header',
message: 'Click to Close',
position: 'top',
buttons: [
{
text: 'Done',
role: 'cancel',
handler: () => {
console.log('Cancel clicked');
}
}
]
});
toast.present();