2017-05-25 64 views
0

我的代碼是正確的瀏覽器,但工作時,我建立使用命令介紹頁面中離子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在聲明和entryComponents然後在運行時它給我錯誤沒有NG模塊IntroPage,但這給了我輸出建立成功(但應用程序只顯示空白頁),如果我保持這IntroPage然後我的代碼是在瀏覽器中正確執行,但版本會爲我的錯誤我上面提到

回答

0

如果您在IntroPage模塊包括IntroPage,你正在實現頁面的延遲加載。

您不應導入或包含在App.module.ts。您也不應在任何其他頁面中導入

App.component.ts,刪除頁面的導入,並在推送頁面時使用字符串等同字符串。

e.g:

 this.rootPage = 'IntroPage'; 

而且您的介紹頁面應該有一個裝飾

@IonicPage() 

檢查here

更多關於延遲加載here