typescript - 嵌套/子组件不是任何 NgModule 的一部分
问题描述
我正在开发 Angular 6 应用程序。我有父组件'Consultation',它在提供者的consultation.module 中被引用,然后我有嵌套组件内部咨询组件和测试组件,它们的引用也在提供者的consultation.module 中,然后是在应用程序中添加的consultation.module 引用。模块。结构如下;
我收到错误 SurveyComponent is not part of any NgModule 即使由于在 component.module 中被引用,不确定我在这里缺少什么???
错误
Error: Component SurveyComponent is not part of any NgModule or the module has not been imported into your module.
咨询模块
@NgModule({
imports:[
CommonModule
],
declarations: [
ConsultationComponent,
SurveyComponent,
TestingComponent
]
})
export class ConsultationModule{
}
App.Module // 根级
@NgModule({
imports: [
ConsultationModule
],
export class AppModule { }
应用程序路由
export const routes: Routes = [
{
path: 'consultation',
component: ConsultationComponent,
data: {
title: 'Consultation'
}
},
{
path: 'survey',
component: SurveyComponent,
data: {
title: 'Survey'
}
}
];
解决方案
the problem you are facing is in here
{
path: 'survey',
component: SurveyComponent,
data: {
title: 'Survey'
}
as you cannot set a path to a component which is nested into another module you need to push that component to the declarations array in app module or you set it into Consultation Module Routing file and would be better to make it lazy loaded
推荐阅读
- php - 如何在 WHERE 中的 sql 查询末尾附加条件并强制其生效?(查询访问控制)
- android - 启动新 Activity 时调用两次 Android Activity 生命周期
- css - 如何在 Angular JS 中更改 SVG 的颜色
- python - 在请求错误回调中处理新项目
- angular - Ant Design 分页(Angular)
- python - 两个 int 对象之间的条件检查
- c# - 静态资源中的数据触发器
- html - 如何选择在 Facebook 中粘贴链接后加载的图像?
- java - Jasper 异常在 AWS EC2 服务器上但不在本地主机上
- c++ - boost crc 每次产生不同的输出