2017-09-05 17 views
0

當我將路由配置詳細信息放入不同的ts文件時,出現以下錯誤。然而,如果我把路由配置放在boot.ts文件中,它工作正常。在將路由配置放入Angular4的單獨ts文件中時發生錯誤

Unhandled Promise rejection: Component DashboardComponent is not part of any NgModule or the module has not been imported into your module. ; Zone: ; Task: Promise.then ; Value: Error: Component DashboardComponent is not part of any NgModule or the module has not been imported into your module.

app.routing.ts:

import { ModuleWithProviders } from '@angular/core'; 
import { RouterModule, Routes } from '@angular/router'; 
import { DashboardComponent } from './Components/dashboard/dashboard.component'; 

const appRoutes: Routes = [ 
    { path: '', redirectTo: 'Dashboard', pathMatch: 'full' }, 
    { path: 'Dashboard', component: DashboardComponent }, 
]; 

export const AppRouting = RouterModule.forRoot(appRoutes, { 
    enableTracing: true 
}); 

boot.ts

//other imports 
import { AppRouting } from './app.routing'; 
@NgModule({ 
imports: [BrowserModule, 
    //AppRouting, 
    RouterModule.forRoot(appRoutes, { enableTracing: true }), // <-- debugging purposes only 
    AgGridModule.forRoot(), 
    MaterialModule, 
    SlimLoadingBarModule.forRoot(), 
    ToastyModule.forRoot(), 
    BrowserAnimationsModule, FormsModule, 
    HttpModule, TreeModule, GrowlModule, FileUploadModule, InputTextModule, ButtonModule, ConfirmDialogModule, NgxChartsModule 
    , AgmCoreModule.forRoot({ apiKey: 'AIzaSyC9TWEHsjWT_QX_Rxl8VXtnnY582aY4mBQ' }) //Angular Google Map Setup 
], 
providers: [BaseComponentService, TreeNodeService, LowryToastyService], 
declarations: [APP_COMPONENTS], 
entryComponents: [ENTRY_COMPONENTS], 
bootstrap: [AppComponent], 
schemas: [CUSTOM_ELEMENTS_SCHEMA] 
}) 
export class AppModule { } 
+0

也許這有幫助嗎? https://stackoverflow.com/questions/39527722/angular-2-component-is-not-part-of-any-ngmodule - >「所以路由認爲它加載了一個不同的組件然後模塊由於大小寫的差異,這意味着被拉進路線的人與模塊不一樣。「 – mwager

+1

感謝你@mwager。它幫助我解決了錯誤。 –

回答

0

您還沒有app.module.ts宣佈 「DashboardComponent」 放這在你的app.module.ts

import { DashboardComponent } from './Components/dashboard/dashboard.component'; 

declarations: [ DashboardComponent ] 
相關問題