Build 离子2生成错误中的简介页

Build 离子2生成错误中的简介页,build,ionic2,declaration,Build,Ionic2,Declaration,我的代码在浏览器中正常工作,但在使用命令生成时 爱奥尼亚cordova构建android——发布——产品 然后它给了我这个错误 '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:

我的代码在浏览器中正常工作,但在使用命令生成时

爱奥尼亚cordova构建android——发布——产品 然后它给了我这个错误

'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.'
应用程序模块.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 {}
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 {}
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();
  }
}
简介模块.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 {}
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 {}
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();
  }
}
应用程序组件.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 {}
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 {}
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中,如果我没有在声明和entryComponents中保留IntroPage,那么在运行时,它会给我错误,没有用于IntroPage的NG模块,但这会给我输出成功构建(但应用程序只显示空白页)如果我保留了IntroPage,那么我的代码在浏览器中正确执行,但是构建给了我上面提到的错误,如果你在IntroPage模块中包含IntroPage,你就实现了页面的延迟加载

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

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

e、 g:

此外,你的介绍页应该有一个装饰

@IonicPage()
检查

更多关于延迟加载的信息