【问题标题】:Ionic 4 error with function for deleting from local storage带有从本地存储删除功能的 Ionic 4 错误
【发布时间】:2018-12-13 22:31:58
【问题描述】:

我正在使用 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'?

【问题讨论】:

    标签: typescript ionic4


    【解决方案1】:

    您应该查看有关 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();
      }
    

    【讨论】:

      猜你喜欢
      • 2021-11-25
      • 1970-01-01
      • 1970-01-01
      • 2014-02-12
      • 2020-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-09
      相关资源
      最近更新 更多