我将 ionic 2 项目迁移到最新版本(即 3.0.0)。一切都很完美,直到我DiscountOption
今天在项目中生成了一个新页面 ( )。它生成了 4 个文件而不是 3 个(*.module.ts 是新的)。
这是我的代码:
折扣option.module.ts
import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { DiscountOption } from './discount-option';
@NgModule({
declarations: [
DiscountOption,
],
imports: [
IonicPageModule.forChild(DiscountOption),
],
exports: [
DiscountOption
]
})
export class DiscountOptionModule { }
app.module.ts
...
import { DiscountOption } from '../pages/orders/biller/discount-option/discount-option';
@NgModule({
declarations: [
...
DiscountOption
],
imports: [
BrowserModule,
HttpModule,
IonicModule.forRoot(MyApp),
IonicStorageModule.forRoot()
],
bootstrap: [IonicApp],
entryComponents: [
...
DiscountOption
],
providers: [
...
]
})
export class AppModule { }
(...为简洁起见缩短了代码)
当我尝试使用构建应用程序时 ionic build android --prod
我收到这个错误,
[11:35:52] ionic-app-script task: "build"
[11:35:52] Error: Type DiscountOption in E:/TFS
SOURCE/HMS/HMS.App/eKot/src/pages/orders/biller/discount-option/discount-option.ts is part of the
declarations of 2 modules: AppModule in E:/TFS SOURCE/HMS/HMS.App/eKot/src/app/app.module.ts and
DiscountOptionModule in E:/TFS
SOURCE/HMS/HMS.App/eKot/src/pages/orders/biller/discount-option/discount-option.module.ts! Please consider
moving DiscountOption in E:/TFS
SOURCE/HMS/HMS.App/eKot/src/pages/orders/biller/discount-option/discount-option.ts to a higher module that
imports AppModule in E:/TFS SOURCE/HMS/HMS.App/eKot/src/app/app.module.ts and DiscountOptionModule in E:/TFS
SOURCE/HMS/HMS.App/eKot/src/pages/orders/biller/discount-option/discount-option.module.ts. You can also
create a new NgModule that exports and includes DiscountOption in E:/TFS
SOURCE/HMS/HMS.App/eKot/src/pages/orders/biller/discount-option/discount-option.ts then import that NgModule
in AppModule in E:/TFS SOURCE/HMS/HMS.App/eKot/src/app/app.module.ts and DiscountOptionModule in E:/TFS
SOURCE/HMS/HMS.App/eKot/src/pages/orders/biller/discount-option/discount-option.module.ts.
Error: Type DiscountOption in E:/TFS SOURCE/HMS/HMS.App/eKot/src/pages/orders/biller/discount-option/discount-option.ts is part of
the declarations of 2 modules: AppModule in E:/TFS SOURCE/HMS/HMS.App/eKot/src/app/app.module.ts and DiscountOptionModule in E:/T
FS SOURCE/HMS/HMS.App/eKot/src/pages/orders/biller/discount-option/discount-option.module.ts! Please consider moving DiscountOptio
n in E:/TFS SOURCE/HMS/HMS.App/eKot/src/pages/orders/biller/discount-option/discount-option.ts to a higher module that imports App
Module in E:/TFS SOURCE/HMS/HMS.App/eKot/src/app/app.module.ts and DiscountOptionModule in E:/TFS SOURCE/HMS/HMS.App/eKot/src/page
s/orders/biller/discount-option/discount-option.module.ts. You can also create a new NgModule that exports and includes DiscountOp
tion in E:/TFS SOURCE/HMS/HMS.App/eKot/src/pages/orders/biller/discount-option/discount-option.ts then import that NgModule in App
Module in E:/TFS SOURCE/HMS/HMS.App/eKot/src/app/app.module.ts and DiscountOptionModule in E:/TFS SOURCE/HMS/HMS.App/eKot/src/page
s/orders/biller/discount-option/discount-option.module.ts.
at Error (native)
at syntaxError (E:\TFS SOURCE\HMS\HMS.App\eKot\node_modules\@angular\compiler\bundles\compiler.umd.js:1513:34)
at CompileMetadataResolver._addTypeToModule (E:\TFS SOURCE\HMS\HMS.App\eKot\node_modules\@angular\compiler\bundles\compiler.um
d.js:14118:31)
at E:\TFS SOURCE\HMS\HMS.App\eKot\node_modules\@angular\compiler\bundles\compiler.umd.js:14007:27
at Array.forEach (native)
at CompileMetadataResolver.getNgModuleMetadata (E:\TFS SOURCE\HMS\HMS.App\eKot\node_modules\@angular\compiler\bundles\compiler
.umd.js:13998:54)
at addNgModule (E:\TFS SOURCE\HMS\HMS.App\eKot\node_modules\@angular\compiler\bundles\compiler.umd.js:22526:58)
at E:\TFS SOURCE\HMS\HMS.App\eKot\node_modules\@angular\compiler\bundles\compiler.umd.js:22537:14
at Array.forEach (native)
at _createNgModules (E:\TFS SOURCE\HMS\HMS.App\eKot\node_modules\@angular\compiler\bundles\compiler.umd.js:22536:26)
我知道这个错误是由于在 app.module 和新生成的模块文件中两次声明了模块。我不知道如何让它工作。任何意见将是有益的。谢谢你。
这是我的离子信息
E:\TFS SOURCE\HMS\HMS.App\eKot> 离子信息
您的系统信息:
Cordova CLI: 6.5.0
Ionic Framework Version: 3.0.0
Ionic CLI Version: 2.2.2
Ionic App Lib Version: 2.2.1
Ionic App Scripts Version: 1.3.0
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Windows 10
Node Version: v6.10.0
Xcode version: Not installed
检查关于 ionic v3的谷歌文档。
DiscountOption
从app.module.ts 中删除对页面的任何引用。
@NgModule({
declarations: [
...
],
imports: [
BrowserModule,
HttpModule,
IonicModule.forRoot(MyApp),
IonicStorageModule.forRoot()
],
bootstrap: [IonicApp],
entryComponents: [
...
],
providers: [
...
]
})
export class AppModule { }
您的页面将在page.module.ts 中被引用和声明
如果要导入的页面其他地方将其删除..使用等效字符串类的name.Also添加@IonicPage()
在DiscountOption
@IonicPage()
@Component({
templateUrl: 'discount-option.html'
})
export class DiscountOption {}
参考:IonicPage
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句