找不到角度模块4

时间:2017-08-18 09:15:50

标签: html5 angular angular2-routing angular-routing angular-module

最初,应用程序显示登录页面并导航到maincontent组件,现在我想从仪表板组件导航到应用程序详细信息组件,但是收到错误

Error: Component DashboardComponent is not part of any NgModule or the module has not been imported into your module.

在我的app.module.ts中,我导入了所有组件

下面是我在app.module.ts

中提到的路线
const appRoutes: Routes=[
    { path:'', redirectTo:'/login',pathMatch:'full'},
    { path: 'login', component: LoginComponent},
    { path: 'maincontent', loadChildren: 
'./maincontent/maincontent.module#MainContentModule'
    }
];
下面的

是MainContentModule

中提到的路线
 export const ROUTES: Routes = [
  {
    path: 'maincontent',
    component: MainContentComponent,
    children: [
      { path: 'dashboard', component:DashboardComponent,
        loadChildren: './dashboard/dashboard.module#DashboardModule' },
        ]
      }
];
@NgModule({
  imports: [
    CommonModule,
    RouterModule.forChild(ROUTES)
  ],
  declarations: [],
  exports:[
    RouterModule,
  ]
})
export class MainContentModule {}

在我的DasboardModule

export const ROUTES: Routes = [
  {
    path:'dashboard', component:DashboardComponent,
    children:[
      {
        path:'application',component:ApplicationDetailsComponent
      }
    ]
  }
]


@NgModule({
  imports: [
    CommonModule,
    RouterModule.forChild(ROUTES)
  ],
  declarations: [   ],
  exports:[
    RouterModule,
  ]
})
export class DashboardModule { }

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:4)

DashboardComponent声明中添加MainContentModule

@NgModule({
  imports: [
    CommonModule,
    RouterModule.forChild(ROUTES)
  ],
  declarations: [DashboardComponent ],
  exports:[
    RouterModule,
  ]
})