解决Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class

写angular项目出现的坑

ERROR in src/app/flying-heroes/flying-heroes.component.ts:9:14 - error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class.

Is it missing an @NgModule annotation?

9 export class FlyingHeroesComponent {
当你出现这种错误时,很有可能是你在app.module.ts 上多写了一步

这是报错时的代码

app.module.ts 
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { FlyingHeroesComponent } from './flying-heroes/flying-heroes.component';


@NgModule({
  declarations: [
    AppComponent,
    FlyingHeroesComponent,
    
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    FlyingHeroesComponent
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

问题就出在 import里写了FlyingHeroesComponent,把它删掉

在这里插入图片描述
就没问题了,原因就是
在NgModule里,有用来描述模块属性的元数据对象,其中最重要的属性是:
1、declarations:用于声明本模块中拥有的视图类,Angular有三种视图类:组件、指令和管道。
2、imports:本模块声明的组件模板需要的类所在的其它模块(导入其他module,其它module暴露的出的Components、Directives、Pipes等可以在本module的组件中被使用。比如导入CommonModule后就可以使用NgIf、NgFor等指令。)

  • 4
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值