Javascript 角度应用程序未构建NGO模块

Javascript 角度应用程序未构建NGO模块,javascript,angular,typescript,Javascript,Angular,Typescript,我有一个角度的应用程序,但我不明白编译器告诉我为什么应用程序不能构建。以下是我从编译器中得到的错误: ERROR in src/app/list-items/list-items.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 anno

我有一个角度的应用程序,但我不明白编译器告诉我为什么应用程序不能构建。以下是我从编译器中得到的错误:

ERROR in src/app/list-items/list-items.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 ListItemsComponent implements OnInit {
               ~~~~~~~~~~~~~~~~~~
src/app/not-found/not-found.component.ts:8: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?

8 export class NotFoundComponent implements OnInit {
               ~~~~~~~~~~~~~~~~~
这是我的
列表项.component.ts
文件:

import { Component, OnInit, NgModule } from '@angular/core';

@Component({
  selector: 'app-list-items',
  templateUrl: './list-items.component.html',
  styleUrls: ['./list-items.component.css']
})
export class ListItemsComponent implements OnInit {

  constructor() { }

  ngOnInit(): void {
  }
}
import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-not-found',
  templateUrl: './not-found.component.html',
  styleUrls: ['./not-found.component.css']
})
export class NotFoundComponent implements OnInit {

  constructor() { }

  ngOnInit(): void {
  }
}
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { HttpClientModule } from '@angular/common/http';  
import { ItemService } from './items.service';
import { NewItemFormComponent } from './new-item-form/new-item-form.component';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
import { MatButtonModule } from '@angular/material/button';
import { MatMenuModule } from '@angular/material/menu';
import { MatIconModule } from '@angular/material/icon';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { FormsModule } from '@angular/forms';
import { NavigationMenuComponent } from './navigation-menu/navigation-menu.component';
import { ListItemsComponent } from './list-items/list-items.component';
import { NotFoundComponent } from './not-found/not-found.component';
import { BrowserModule } from '@angular/platform-browser';

const appRoutes: Routes = [ {
  path: '',                     //default component to display
   component: ListItemsComponent
 },       {
   path: 'addItem',         //when items added 
   component: NewItemFormComponent
 },       {
   path: 'listItems',       //when items listed
   component: ListItemsComponent
 },       {
   path: '**',                 //when path cannot be found
   component: NotFoundComponent
 }
];

@NgModule({
  declarations: [
    AppComponent,
    NewItemFormComponent,
    NavigationMenuComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    HttpClientModule,
    MatFormFieldModule,
    MatInputModule,
    MatButtonModule,
    MatIconModule,
    MatMenuModule,
    BrowserAnimationsModule,
    FormsModule,
    RouterModule.forRoot(appRoutes),
    ListItemsComponent,
    NotFoundComponent
  ],

  providers: [ItemService],
  bootstrap: [AppComponent]
})
export class AppModule { }
这是我的
未找到.component.ts
文件:

import { Component, OnInit, NgModule } from '@angular/core';

@Component({
  selector: 'app-list-items',
  templateUrl: './list-items.component.html',
  styleUrls: ['./list-items.component.css']
})
export class ListItemsComponent implements OnInit {

  constructor() { }

  ngOnInit(): void {
  }
}
import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-not-found',
  templateUrl: './not-found.component.html',
  styleUrls: ['./not-found.component.css']
})
export class NotFoundComponent implements OnInit {

  constructor() { }

  ngOnInit(): void {
  }
}
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { HttpClientModule } from '@angular/common/http';  
import { ItemService } from './items.service';
import { NewItemFormComponent } from './new-item-form/new-item-form.component';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
import { MatButtonModule } from '@angular/material/button';
import { MatMenuModule } from '@angular/material/menu';
import { MatIconModule } from '@angular/material/icon';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { FormsModule } from '@angular/forms';
import { NavigationMenuComponent } from './navigation-menu/navigation-menu.component';
import { ListItemsComponent } from './list-items/list-items.component';
import { NotFoundComponent } from './not-found/not-found.component';
import { BrowserModule } from '@angular/platform-browser';

const appRoutes: Routes = [ {
  path: '',                     //default component to display
   component: ListItemsComponent
 },       {
   path: 'addItem',         //when items added 
   component: NewItemFormComponent
 },       {
   path: 'listItems',       //when items listed
   component: ListItemsComponent
 },       {
   path: '**',                 //when path cannot be found
   component: NotFoundComponent
 }
];

@NgModule({
  declarations: [
    AppComponent,
    NewItemFormComponent,
    NavigationMenuComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    HttpClientModule,
    MatFormFieldModule,
    MatInputModule,
    MatButtonModule,
    MatIconModule,
    MatMenuModule,
    BrowserAnimationsModule,
    FormsModule,
    RouterModule.forRoot(appRoutes),
    ListItemsComponent,
    NotFoundComponent
  ],

  providers: [ItemService],
  bootstrap: [AppComponent]
})
export class AppModule { }
这是我的
app.module.ts
文件:

import { Component, OnInit, NgModule } from '@angular/core';

@Component({
  selector: 'app-list-items',
  templateUrl: './list-items.component.html',
  styleUrls: ['./list-items.component.css']
})
export class ListItemsComponent implements OnInit {

  constructor() { }

  ngOnInit(): void {
  }
}
import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-not-found',
  templateUrl: './not-found.component.html',
  styleUrls: ['./not-found.component.css']
})
export class NotFoundComponent implements OnInit {

  constructor() { }

  ngOnInit(): void {
  }
}
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { HttpClientModule } from '@angular/common/http';  
import { ItemService } from './items.service';
import { NewItemFormComponent } from './new-item-form/new-item-form.component';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
import { MatButtonModule } from '@angular/material/button';
import { MatMenuModule } from '@angular/material/menu';
import { MatIconModule } from '@angular/material/icon';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { FormsModule } from '@angular/forms';
import { NavigationMenuComponent } from './navigation-menu/navigation-menu.component';
import { ListItemsComponent } from './list-items/list-items.component';
import { NotFoundComponent } from './not-found/not-found.component';
import { BrowserModule } from '@angular/platform-browser';

const appRoutes: Routes = [ {
  path: '',                     //default component to display
   component: ListItemsComponent
 },       {
   path: 'addItem',         //when items added 
   component: NewItemFormComponent
 },       {
   path: 'listItems',       //when items listed
   component: ListItemsComponent
 },       {
   path: '**',                 //when path cannot be found
   component: NotFoundComponent
 }
];

@NgModule({
  declarations: [
    AppComponent,
    NewItemFormComponent,
    NavigationMenuComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    HttpClientModule,
    MatFormFieldModule,
    MatInputModule,
    MatButtonModule,
    MatIconModule,
    MatMenuModule,
    BrowserAnimationsModule,
    FormsModule,
    RouterModule.forRoot(appRoutes),
    ListItemsComponent,
    NotFoundComponent
  ],

  providers: [ItemService],
  bootstrap: [AppComponent]
})
export class AppModule { }

是否有人碰巧了解编译器试图告诉我的有关
NgModule
的内容?

从app.modules文件的导入部分删除这两个组件,并将它们移动到声明中

您没有创建自定义模块;您只是在创建一个组件。以正确的方式导入它,您将不会再有任何问题

我还建议您使用angular cli生成器生成新组件

ng generate component test

从app.modules文件的导入部分删除这两个组件,并将它们移动到声明中

您没有创建自定义模块;您只是在创建一个组件。以正确的方式导入它,您将不会再有任何问题

我还建议您使用angular cli生成器生成新组件

ng generate component test

请共享您的app.modules.ts中的代码错误很可能在那里。您好,上面已添加。请共享您的app.modules.ts中的代码错误很可能在那里。您好,上面已添加。