【发布时间】:2022-01-18 15:13:24
【问题描述】:
我是 Angular 的新手。我创建了页眉、页脚和侧边栏。如果我在这个 dishoard 组件中使用它,我正在创建仪表板组件。所以它在组件中工作。然后我为员工创建了一个模块。如果我在这个员工模块中使用页眉页脚边栏意味着它的显示错误
- 如果 'app-header' 是一个 Angular 组件,则验证它是该模块的一部分。
- 如果“app-header”是 Web 组件,则将“CUSTOM_ELEMENTS_SCHEMA”添加到该组件的“@NgModule.schemas”以禁止显示此消息。
1
src/app/employee/list-employee/list-employee.component.ts:5:16
5 templateUrl: './list-employee.component.html',
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Error occurs in the template of component ListEmployeeComponent.
Error: src/app/employee/list-employee/list-employee.component.html:2:1 - error NG8001: 'app-sidebar' is not a known element:
1. If 'app-sidebar' is an Angular component, then verify that it is part of this module.
2. If 'app-sidebar' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
2 <app-sidebar></app-sidebar>
src/app/employee/list-employee/list-employee.component.ts:5:16 5 templateUrl: './list-employee.component.html', ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 组件ListEmployeeComponent的模板出错。
错误:src/app/employee/list-employee/list-employee.component.html:514:9 - 错误 NG8001:'app-footer' 不是已知元素:
- 如果“app-footer”是一个 Angular 组件,则验证它是该模块的一部分。
- 如果“app-footer”是 Web 组件,则将“CUSTOM_ELEMENTS_SCHEMA”添加到该组件的“@NgModule.schemas”以禁止显示此消息。
514 ~~~~~~~~~~~~
src/app/employee/list-employee/list-employee.component.ts:5:16 5 templateUrl: './list-employee.component.html', ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 组件ListEmployeeComponent的模板出错。
请帮我解决这个错误。
【问题讨论】:
-
您应该将页眉、页脚和侧边栏组件放在一个单独的模块中,您可以将其导入所有具有需要显示它们的组件的模块中。
-
我分别创建了页眉、页脚、侧边栏组件。
-
在另一个模块中?然后您需要做的就是在
EmployeeModule中导入声明(并导出)这些组件的模块,它应该可以工作。
标签: javascript angular