2017-08-07 115 views
0

運行命令下面的工作原理: ionic cordova build ios離子3模塊聲明錯誤

但在以下錯誤

Error: Type ExpandableHeaderComponent in /Users/jobstore/jobstore/js/src/components/expandable-header/expandable-header.ts is part of the declarations of 2 modules: SharedModuleComponent in /Users/jobstore/jobstore/js/src/components/shared-module/shared-module.ts and ExpandableHeaderComponentModule in /Users/jobstore/jobstore/js/src/components/expandable-header/expandable-header.module.ts! Please consider moving ExpandableHeaderComponent in /Users/jobstore/jobstore/js/src/components/expandable-header/expandable-header.ts to a higher module that imports SharedModuleComponent in /Users/jobstore/jobstore/js/src/components/shared-module/shared-module.ts and ExpandableHeaderComponentModule in /Users/jobstore/jobstore/js/src/components/expandable-header/expandable-header.module.ts. You can also create a new NgModule that exports and includes ExpandableHeaderComponent in /Users/jobstore/jobstore/js/src/components/expandable-header/expandable-header.ts then import that NgModule in SharedModuleComponent in /Users/jobstore/jobstore/js/src/components/shared-module/shared-module.ts and ExpandableHeaderComponentModule in /Users/jobstore/jobstore/js/src/components/expandable-header/expandable-header.module.ts.

我試圖創建共享模塊運行以下

ionic cordova build ios --prod 

結果:

import { Component ,NgModule} from '@angular/core'; 
import {ExpandableHeaderComponent} from '../expandable-header/expandable-header'; 
import {ShrinkHeaderComponent} from '../shrink-header/shrink-header'; 


@Component({ 
    selector: 'shared-module', 
    templateUrl: 'shared-module.html' 
}) 



@NgModule({ 
    declarations: [ 
    ExpandableHeaderComponent, 
    ShrinkHeaderComponent 

    ], 

    exports: [ 
    ExpandableHeaderComponent, 
    ShrinkHeaderComponent 
    ] 

}) 

export class SharedModuleComponent { 

    constructor() { 
    } 

} 

和app.module.ts

其導入

這裏

import { SharedModuleComponent } from '../components/shared-module/shared-module'; 

這裏

 imports: [ 
    BrowserModule, 
    HttpModule, 
    SharedModuleComponent, 
    ], 

,但我仍然面臨着同樣的問題。

+0

聲明它。你的錯誤正好說明你應該做什麼。這裏不清楚什麼? – yurzui

+0

你可以顯示你的ComponentsModule嗎? – brijmcq

+0

@yurzui,你可以請你幫我理解 – noor

回答

0

的這個錯誤告訴你需要做什麼。除此之外,我注意到您爲ExpandableHeaderComponent創建了另一個模塊。如果你不懶惰加載你的模塊,最好只是在你的SharedModule或直接對你的AppModule

+0

我的ExpandableHeaderComponent最初只是在AppModule中調用,但是當我在--prod中運行應用程序時。它拋出了相同的錯誤,所以我做了一個sharedModule。但它不工作 – noor

+0

我想我不明白什麼時候錯誤說導入到一個更高的模塊。這是什麼意思? – noor

+0

用您提供的信息很難說。基本上,你應該只在一個模塊中聲明它或者你的sharedmodule或者appmodule。您可能會錯過 – brijmcq