离子 2 构建错误中的介绍页面



我的代码在浏览器中工作正常,但是当我使用命令构建时

ionic cordova build android --release --prod然后它给了我这个错误

'Error: Type IntroPage in D:/Ionic Work/xxx/src/pages/intro/intro.ts is part of the declarations of 2 modules: AppModule in D:/Ionic Work/xxx/src/app/app.module.ts and IntroPageMod in D:/Ionic Work/xxx/src/pages/intro/intro.module.ts! Please consider moving IntroPage in D:/Ionic Work/xxx/src/pages/intro/intro.ts to a higher module that imports AppModule in D:/Ionic Work/xxx/src/app/app.module.ts and IntroPageModule in D:/Ionic Work/xxx/src/pages/intro/intro.module.ts. You can also create a new NgModule that exports and includes IntroPage in D:/Ionic Work/xxx/src/pages/intro/intro.ts then import that NgModule in AppModule in D:/Ionic Work/xxx/src/app/app.module.ts and IntroPageModule in D:/Ionic Work/xxx/src/page/intro/intro.module.ts.'

App.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { IonicStorageModule } from '@ionic/storage';
import { SplashScreen } from '@ionic-native/splash-screen';
import { StatusBar } from '@ionic-native/status-bar';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { IntroPage } from '../pages/intro/intro';
@NgModule({
  declarations: [
    MyApp,
    HomePage,
    IntroPage
  ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp),
    IonicStorageModule.forRoot()
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    HomePage,
    IntroPage
  ],
  providers: [
    StatusBar,
    SplashScreen,
    {provide: ErrorHandler, useClass: IonicErrorHandler}
  ]
})
export class AppModule {}

Intro.module.ts

import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { IntroPage } from './intro';
@NgModule({
  declarations: [
    IntroPage,
  ],
  imports: [
    IonicPageModule.forChild(IntroPage),
  ],
  exports: [
    IntroPage
  ]
})
export class IntroPageModule {}

App.component.ts

import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { LoadingController } from 'ionic-angular';
import { Storage } from '@ionic/storage';
import { SplashScreen } from '@ionic-native/splash-screen';
import { HomePage } from '../pages/home/home';
import { IntroPage } from '../pages/intro/intro';
@Component({
  templateUrl: 'app.html'
})
export class MyApp {
  rootPage: any = HomePage;
  loader: any;
  constructor(public platform: Platform, public loadingCtrl: LoadingController,public storage: Storage, public splashScreen: SplashScreen) {
    console.log("Here");
    this.presentLoading();
    this.platform.ready().then(() => {
        this.storage.get('introshown').then((result) => {
        if(result){
            console.log("in if");
            this.rootPage = HomePage;
        }  else{
            console.log("in else");
            this.rootPage = IntroPage;
            this.storage.set('introshown',true);
        }
        this.loader.dismiss();
      });
    });
  }
  presentLoading() {
      this.loader = this.loadingCtrl.create({
          content: "Authenticating .... "
      });
      this.loader.present();
  }
}

现在在 App.module.ts 中,如果我没有在声明和条目组件中保留 IntroPage,那么在运行时它会给我错误,即没有用于 IntroPage 的 NG 模块,但这给了我成功输出构建(但应用程序只显示空白页(,如果我保留该 IntroPage,那么我的代码浏览器中正确执行,但构建给了我错误我上面提到的

如果您在IntroPage模块中包含IntroPage,则正在实现页面的延迟加载。

不应导入或包含在 App.module.ts 中。您也不应该在任何其他页面中导入。

App.component.ts 中,删除页面的导入,并在推送页面时使用字符串文本等效项。

例如:

        this.rootPage = 'IntroPage';

此外,您的介绍页面应该有一个装饰器

@IonicPage()

在这里查看

有关延迟加载的更多信息,请点击此处。

相关内容

  • 没有找到相关文章

最新更新