Angular 无法加载自定义模块
Angular custom module cannot be loaded
对大多数人来说可能很明显,但我自己仍然找不到。
我有一个angular申请和以下相关文件
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 中的所有内容 imported/declared 都可用于整个应用程序。
根据文件名,我的猜测是您在此处使用了错误的名称:
<app-dashboard-stats-tile></app-dashboard-stats-tile>
此组件 .ts
文件的名称将是 "dashboard-stats-tile.ts"。
您可能希望将此行替换为:
<app-stats-tile></app-stats-tile>
对大多数人来说可能很明显,但我自己仍然找不到。
我有一个angular申请和以下相关文件
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 中的所有内容 imported/declared 都可用于整个应用程序。
根据文件名,我的猜测是您在此处使用了错误的名称:
<app-dashboard-stats-tile></app-dashboard-stats-tile>
此组件 .ts
文件的名称将是 "dashboard-stats-tile.ts"。
您可能希望将此行替换为:
<app-stats-tile></app-stats-tile>