2017-08-24 61 views
0

我已將我的app.module.ts分成多個模塊,但是這會導致我無法解決的錯誤。我得到的錯誤:Angular2 ngModule split會導致錯誤

Template parse errors: 'generic-titlepagebar' is not a known element

這是我的模塊,這些模塊使用仿製titlepagebar。

app.modules.ts:

@NgModule({ 
    declarations: [ 
    AppComponent, 
    LoginComponent 
    ], 
    imports: [ 
    BrowserModule, 
    MaterialModule, 
    FormsModule, 
    ReactiveFormsModule, 
    HttpModule, 
    BrowserAnimationsModule, 
    MdNativeDateModule, 
    Md2Module, 
    ResponsiveModule, 
    DataTableModule, 
    GridsterModule, 
    NgbDropdownModule.forRoot(), 
    AgmCoreModule.forRoot({ 
     apiKey: 'AIzaSyD2lf1s8D8vkzHKxDWfkHqGAGsGLAWlNvw' 
    }), 
    CustomComponentsModule, 
    GenericComponentsModule, 
    ViewModule, 
    ServiceModule, 
    RouterModule.forRoot(appRoutes), 
    ], 
    providers: [ 
    { 
     provide: Http, 
     useFactory: httpFactory, 
     deps: [XHRBackend, RequestOptions] 
    } 
    ], 
    bootstrap: [ 
    AppComponent 
    ] 
}) 
export class AppModule { } 

和通用-component.module.ts

@NgModule({ 
    imports: [ 
    CommonModule, 
    MaterialModule, 
    FormsModule, 
    ReactiveFormsModule, 
    HttpModule, 
    BrowserAnimationsModule, 
    RouterModule, 
    MdNativeDateModule, 
    Md2Module, 
    ResponsiveModule, 
    DataTableModule, 
    GridsterModule, 
    NgbDropdownModule.forRoot(), 
    AgmCoreModule.forRoot({ 
     apiKey: 'AIzaSyD2lf1s8D8vkzHKxDWfkHqGAGsGLAWlNvw' 
    }) 
    ], 
    declarations: [ 
    BackButtonComponent, 
    DynamicFormComponent, 
    DynamicFormQuestionComponent, 
    DynamicLoaderComponent, 
    GenericCardComponent, 
    GenericConfigComponent, 
    GenericListComponent, 
    GenericProjectSwitcherComponent, 
    GenericSearchComponent, 
    MapsComponent, 
    TableComponent, 
    TableDetailsComponent, 
    TabsbarComponent, 
    TitlePageBarComponent, 
    MenuComponent 
    ], 
    entryComponents: [ 
    GenericListComponent, 
    DynamicFormComponent, 
    GenericCardComponent, 
    GenericSearchComponent, 
    TableComponent 
    ] 
}) 
export class GenericComponentsModule {} 

回答

0

如果你有在你的仿製組件選擇 '仿製titlepagebar' 的成分.module,您需要將此組件添加到generic-component.module的@NgModule聲明的exports部分中。然後,您可以在app.module中的某個組件的模板中使用標記<generic-titlepagebar>

+0

我試着將它添加爲:exports:[GenericComponentsModule],但Module已經導出爲導出類GenericComponentsModule {} – viddrawings

+0

您需要將具有選擇器的組件:'generic-titlepagebar'(不是模塊)放入出口 –

+0

我也試過,但它似乎也沒有工作... – viddrawings