2017-05-25 43 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