对于大多数人来说可能很明显,但我自己仍然找不到。
我有一个角度应用程序和以下相关文件
app/app.module.ts
app/dashboard/dashboard.component.html
app/dashboard/stats-tile/stats-tile.component.html
我使用ng generate生成了stats-tile组件,因此在导入的app.module.ts中以及声明中:
//app.module.ts
declarations: [
AppComponent,
TournamentSearchComponent,
DashboardComponent,
StatsTileComponent
],
现在,我要显示stats-tile组件
//dashboard.component.html
<app-dashboard-stats-tile></app-dashboard-stats-tile>
我得到:
Error: Template parse errors:
'app-dashboard-stats-tile' is not a known element:
我究竟做错了什么。我可以使用我在应用程序组件中生成的另一个组件。我在子文件夹中生成它时有什么区别吗? 我对angular有点陌生,但我的理解是app.module.ts中导入/声明的所有内容都可用于整个应用程序。
根据文件名,我的猜测是您在此处使用了错误的名称:
The name of this component
.ts
file would be "dashboard-stats-tile.ts".您可能希望将此行替换为: