【发布时间】:2019-09-27 06:40:15
【问题描述】:
我有 2 个模块 AppModule 和 MyArtModule,其中声明了一些组件。
当我尝试在GraphicsComponent 中使用ConfirmComponent 选择器时,它工作正常,但是当我尝试在MyArtComponent 中使用ConfirmComponent 选择器时,它抛出错误'artifi-confirm-alert' is not a known element:
'artifi-confirm-alert' 不是已知元素:
如果 'artifi-confirm-alert' 是一个 Angular 组件,则验证它是该模块的一部分。
如果“artifi-confirm-alert”是 Web 组件,则将“CUSTOM_ELEMENTS_SCHEMA”添加到该组件的“@NgModule.schemas”中 禁止显示此消息。
- 应用模块
- 图形组件
- 确认组件
- MyArt 模块
- 我的艺术组件
AppModule 代码
@NgModule({
declarations: [
GraphicsComponent,
ConfirmAlertComponent
],
imports: [
BrowserModule,
MyArtModule
],
...
})
MyArtModule 代码
@NgModule({
declarations: [
MyArtComponent,
],
imports: [
CommonModule
],
providers: [
MyArtService
],
exports: [
MyArtComponent
]
})
复制的问题代码 - https://stackblitz.com/edit/skdroid-childmodule-in-child-component
我已经创建了 OneModule 和 OneComponent 和 TwoModule 和 TwoComponent。
<app-one></app-one> 和 <app-two></app-two> 可以在 AppComponent 中访问。
但无法访问 AppOne 组件中的<app-two></app-two>。
【问题讨论】: