【问题标题】:Is the "IonApp" class from @ionic/angular (Ionic 4) the new "App" class from ionic-angular ( Ionic 3)?@ionic/angular(Ionic 4)中的“IonApp”类是 ionic-angular(Ionic 3)中的新“App”类吗?
【发布时间】:2019-09-25 05:42:28
【问题描述】:

我目前正在尝试将旧的 Ionic 应用迁移到 Ionic 4。

在迁移之前它们完全没有问题

我正在处理提供程序文件 helper.ts,但遇到了迁移问题。

这是离子信息输出


Ionic:

   ionic (Ionic CLI)             : 4.12.0 (/usr/lib/node_modules/ionic)
   Ionic Framework               : @ionic/angular 4.3.1
   @angular-devkit/build-angular : 0.13.8
   @angular-devkit/schematics    : 7.3.8
   @angular/cli                  : 7.3.8
   @ionic/angular-toolkit        : 1.5.1

System:

   NodeJS : v10.12.0 (/usr/bin/node)
   npm    : 6.9.0
   OS     : Linux 4.13

在旧应用中我必须导入

import { App, MenuController } from 'ionic-angular';

在 ionic 4 中 ionic-angular 被替换为 @ionic/angular ,但 App 不再存在。

import { App, MenuController } from '@ionic/angular';

会导致错误:

ERROR in src/services/helper.ts(2,10): error TS2305: Module 'URLmodule' has no exported member 'App'.

所以我尝试导入另一个类,IonApp,但是这个类似乎没有相同的功能

import { IonApp, MenuController } from '@ionic/angular';

会导致错误:

ERROR in src/services/helper.ts(18,18): error TS2339: Property 'getRootNav' does not exist on type 'IonApp'.

我想知道 IonApp 是否是正确的成员,我必须覆盖它,或者 App 成员是否在 Ionic 4 中消失了?

这是新的 helper.ts。

import { Injectable } from '@angular/core';
import { IonApp, MenuController } from '@ionic/angular';
import { Storage } from '@ionic/storage';

import { HomePage } from '../app/home/home.page';

@Injectable({
  providedIn: 'root',
})
export class Helper {

  constructor(private app: IonApp, private menuCtrl: MenuController, private storage: Storage) { }

    /**
     * go to HomePage, no matter where u are
    */
    previousPage() {
        this.app.getRootNav().setRoot(HomePage, {}, {animate: true, direction: 'forward'});
    }

    // menu handler, because we have two
    openMenu(menu) {
        this.menuCtrl.enable(true, 'menu-map');
        this.menuCtrl.open('menu-map');
    }

    closeMenu(menu) {
        this.menuCtrl.close('menu-map');
        this.menuCtrl.enable(false, 'menu-map');
    }

    storeStats(article) {
       this.storage.get('processStats').then((val) => {
            let find = false;
            for(let i=0; i < val.length; i++) {
                if(article.code === val[i].code) {
                    let array = val;
                    array[i].view = val[i].view + 1;
                    this.storage.set('processStats', array);
                    find = true;
                    break;
                }
            }
            if(find === false) {
                let array = val;
                array.push({code: article.code, title: article.title, view: 1, notFound: 0})
                this.storage.set('processStats', array)
            }
       })
    }

    notFoundStats(article) {
        this.storage.get('processStats').then((val) => {
            for(let i=0; i < val.length; i++) {
                if(article.code === val[i].code) {
                    let array = val;
                    array[i].notFound = val[i].notFound + 1;
                    this.storage.set('processStats', array);
                    break;
                }
            }
        });
    }

    initialiseStats() {
         this.storage.set('processStats', [{code: "", title: "", view: 0, notFound: 0}])
    }
}

【问题讨论】:

    标签: angular ionic3 migration ionic4 code-migration


    【解决方案1】:

    您好 ionic 4,您需要使用 this.appCtrl.getActiveNav 到 this.appCtrl.navigateRoot 并从“ionic-angular”导入 { App,}; 从 '@ionic/angular' 导入 { NavController };

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-09
      • 1970-01-01
      • 1970-01-01
      • 2020-05-21
      • 1970-01-01
      • 2023-03-17
      • 2018-04-10
      • 2018-03-28
      相关资源
      最近更新 更多