无法加载Angular自定义模块

问题描述 投票:0回答:1

可能对大多数人来说是显而易见的,但我自己还是找不到。

我有一个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:

我做错了什么。我能够使用我在app组件中生成的另一个组件。当我在子文件夹中生成它时,是否有一些不同?我对angular有点陌生,但我的理解是,app.module.ts中的所有importeddeclared都对整个app可用。

angular angular-components
1个回答
1
投票

根据这些文件的名称,我猜测你在这里用错了名字。

<app-dashboard-stats-tile></app-dashboard-stats-tile>

这个组件的名字 .ts 文件将是 "dashboard-stats-tile.ts"。

你可能想把这行替换为

<app-stats-tile></app-stats-tile>
© www.soinside.com 2019 - 2024. All rights reserved.