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然後我的代碼是在瀏覽器中正確執行,但版本會爲我的錯誤我上面提到