0.背景
调试angular项目时,报这个错。子组件的引用是正确的,可是还是报这个错误。
组件是使用ng g m创建的。
1.解决办法
查看你的xxx.module.ts中是否正确引用了子组件。正确的做法是:
import { NgModule } from ‘@angular/core’;
import { ListComponent } from ‘./list/list.component’;
@NgModule({
declarations: [ListComponent],
imports: [
xxxxRoutingModule
],
exports: [ListComponent],
})
先使用import导入组件,然后在declarations中和exports 写组件的名字。