Component Xxx is not part of any NgModule or the module has not been imported into your module.

原文链接:这里

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 写组件的名字。

 

posted on 2022-02-01 19:43  longkui  阅读(151)  评论(0编辑  收藏  举报

导航