解决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,把它删掉

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

你可能感兴趣的:(typescript,angular,node.js)