Ionic 4 错误,具有从本地存储中删除的功能
Ionic 4 error with function for deleting from local storage
我正在使用 Ionic v4 制作一个应用程序,并且正在制作删除用户已添加到收藏夹的项目的功能。当我在命令提示符下 运行 ionic serve 时出现错误。
我对 Ionic 很陌生
我的delete.ts
文件
deleteFavorite(item: ItemSliding, id: number) {
console.log('delete', id);
let alert = this.alertCtrl.create({
message: 'Do you want to delete this favorite cabin?',
buttons: [
{
text: 'Cancel',
role: 'cancel',
handler: () => {
console.log('Delete cancelled')
}
},
{
text: 'Delete',
handler: () => {
let loading = this.loadCtrl.create({
});
let toast = this.toastCtrl.create({
message: 'Cabin ' + id + ' deleted successfully',
duration: 3000
});
loading.present(); /*first error*/
this.favservice.deleteFavorite(id)
.subscribe(favs => {
this.favorites = favs;
loading.dismiss(); /* second error*/
toast.present(); /* third error*/
} , errMsg => {
this.errMsg = errMsg;
loading.dismiss(); /* fourth error*/
});
}
}
]
}).then(alert => alert.present());
item.close();
}
我的错误
[ng] ERROR in src/app/pages/favorites/favorites.page.ts(57,21): error TS2570: Property 'present' does not exist on type 'Promise<HTMLIonLoadingElement>'. Did you forget to use 'await'?
[ng] src/app/pages/favorites/favorites.page.ts(62,24): error TS2570: Property 'dismiss' does not exist on type 'Promise<HTMLIonLoadingElement>'. Did you forget to use 'await'?
[ng] src/app/pages/favorites/favorites.page.ts(63,22): error TS2570: Property 'present' does not exist on type 'Promise<HTMLIonToastElement>'. Did you forget to use 'await'?
[ng] src/app/pages/favorites/favorites.page.ts(66,24): error TS2570: Property 'dismiss' does not exist on type 'Promise<HTMLIonLoadingElement>'. Did you forget to use 'await'?
您应该查看有关 AlertController 的官方 Ionic 4 文档。我认为您在新的 Ionic 4 中混淆了 Ionic 3 文档。
https://beta.ionicframework.com/docs/api/alert
这是在 Ionic 4 中使用简单的 alertController 的方式:
async presentAlert() {
const alert = await this.alertController.create({
header: 'Alert',
subHeader: 'Subtitle',
message: 'This is an alert message.',
buttons: ['OK']
});
await alert.present();
}
我正在使用 Ionic v4 制作一个应用程序,并且正在制作删除用户已添加到收藏夹的项目的功能。当我在命令提示符下 运行 ionic serve 时出现错误。
我对 Ionic 很陌生
我的delete.ts
文件
deleteFavorite(item: ItemSliding, id: number) {
console.log('delete', id);
let alert = this.alertCtrl.create({
message: 'Do you want to delete this favorite cabin?',
buttons: [
{
text: 'Cancel',
role: 'cancel',
handler: () => {
console.log('Delete cancelled')
}
},
{
text: 'Delete',
handler: () => {
let loading = this.loadCtrl.create({
});
let toast = this.toastCtrl.create({
message: 'Cabin ' + id + ' deleted successfully',
duration: 3000
});
loading.present(); /*first error*/
this.favservice.deleteFavorite(id)
.subscribe(favs => {
this.favorites = favs;
loading.dismiss(); /* second error*/
toast.present(); /* third error*/
} , errMsg => {
this.errMsg = errMsg;
loading.dismiss(); /* fourth error*/
});
}
}
]
}).then(alert => alert.present());
item.close();
}
我的错误
[ng] ERROR in src/app/pages/favorites/favorites.page.ts(57,21): error TS2570: Property 'present' does not exist on type 'Promise<HTMLIonLoadingElement>'. Did you forget to use 'await'?
[ng] src/app/pages/favorites/favorites.page.ts(62,24): error TS2570: Property 'dismiss' does not exist on type 'Promise<HTMLIonLoadingElement>'. Did you forget to use 'await'?
[ng] src/app/pages/favorites/favorites.page.ts(63,22): error TS2570: Property 'present' does not exist on type 'Promise<HTMLIonToastElement>'. Did you forget to use 'await'?
[ng] src/app/pages/favorites/favorites.page.ts(66,24): error TS2570: Property 'dismiss' does not exist on type 'Promise<HTMLIonLoadingElement>'. Did you forget to use 'await'?
您应该查看有关 AlertController 的官方 Ionic 4 文档。我认为您在新的 Ionic 4 中混淆了 Ionic 3 文档。
https://beta.ionicframework.com/docs/api/alert
这是在 Ionic 4 中使用简单的 alertController 的方式:
async presentAlert() {
const alert = await this.alertController.create({
header: 'Alert',
subHeader: 'Subtitle',
message: 'This is an alert message.',
buttons: ['OK']
});
await alert.present();
}