当我将路由配置详细信息放在不同的ts文件中时出现以下错误。但是,如果我将路由配置放在boot.ts文件中,它可以正常工作。
未处理的承诺拒绝:组件DashboardComponent不是其中的一部分 任何NgModule或模块尚未导入您的模块。 ;区域:;任务:Promise.then;值:错误:组件 DashboardComponent不是任何NgModule的一部分,或者模块没有 已导入您的模块。
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 :(得分:0)
您尚未在app.module.ts中声明“DashboardComponent” 把它放在你的app.module.ts
中import { DashboardComponent } from './Components/dashboard/dashboard.component';
declarations: [ DashboardComponent ]