【发布时间】:2020-03-21 03:35:27
【问题描述】:
这里有一些代码片段。
组件:
import { Component } from '@angular/core';
@Component({
selector: 'app-generalstatistics',
templateUrl: './generalstatistics.component.html',
styleUrls: ['./generalstatistics.component.css']
})
export class Generalstatistics {
public data: Array<Object>;
constructor() { }
}
app.module.ts:
import { Generalstatistics } from './views/generalstatistics/generalstatistics.component';
declarations: [
....
Generalstatistics
],
在 DashboardModule/DashboardComponent.html 中的实现:
<div class="chart-wrapper mt-3 mx-3" style="height:70px;">
<app-generalstatistics></app-generalstatistics>
</div>
错误:
core.js:4002 ERROR Error: Uncaught (in promise): Error: Template parse errors:
'app-generalstatistics' is not a known element:
1. If 'app-generalstatistics' is an Angular component, then verify that it is part of this module.
2. If 'app-generalstatistics' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the
'@NgModule.schemas' of this component to suppress this message. ("
</div>
<div class="chart-wrapper mt-3 mx-3" style="height:70px;">
[ERROR ->]<app-generalstatistics></app-generalstatistics>
</div>
</div>
"): ng:///DashboardModule/DashboardComponent.html
我到底做错了什么?
感谢您的帮助。
【问题讨论】:
-
我假设您也应该将
app-generalstatistics组件添加到您的DashboardModule的declaration: []中。 NgModule 是模板 afaik 的编译上下文,因此我们必须在使用它的每个模块中声明一个组件。否则编译可能需要一段时间,因为在这种情况下,Angular 将不得不去搜索组件。它可能存在任何依赖关系,包括第 3 方。
标签: angular angular-components