NG002错误:无法解析为NgModule类

时间:2020-04-02 15:57:09

标签: javascript angular typescript

我在我的角度项目中添加了一个新组件,并确保将其导入到我的应用程序模块中,但是出现NG002错误:

error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class.

Is it missing an @NgModule annotation?

export class NavigationBarDriverComponent {

我的应用程序模块如下:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
import {GoogleMapsAPIWrapper} from '@agm/core';
import { AppComponent } from './app.component';
import { ButtonComponent } from './button/button.component';
import { AgmCoreModule } from '@agm/core';
import { AgmDirectionModule } from 'agm-direction';
import { GooglePlaceModule } from "ngx-google-places-autocomplete";
import { NavigationBarComponent } from './navigation-bar/navigation-bar.component';
import { NavigationBarDriverComponent} from './navigation-bar-driver/navigation-bar-driver.component';
import { LayoutModule } from '@angular/cdk/layout';
import { MatToolbarModule } from '@angular/material/toolbar';
import { MatButtonModule } from '@angular/material/button';
import { MatSidenavModule } from '@angular/material/sidenav';
import { MatIconModule } from '@angular/material/icon';
import { MatListModule } from '@angular/material/list';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { OwlDateTimeModule, OwlNativeDateTimeModule } from 'ng-pick-datetime';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

import { MatDialogModule } from '@angular/material/dialog';
import { RouteDialogComponent } from './route-dialog/route-dialog.component';

import { AppRoutingModule, routingComponents } from './app-routing.module';

@NgModule({
  declarations: [
    AppComponent,
    ButtonComponent,
    NavigationBarComponent,
    NavigationBarDriverComponent,
    RouteDialogComponent,
    routingComponents
  ],
  imports: [
    BrowserModule,
    AgmCoreModule.forRoot({
      apiKey: 'AIzaSyDnibzvTPaquvcrp9ZYZZ5EFgzncyK1jys'
    }),
    AgmDirectionModule,
    GooglePlaceModule,
    LayoutModule,
    MatToolbarModule,
    MatButtonModule,
    MatSidenavModule,
    MatIconModule,
    MatListModule,
    NoopAnimationsModule,
    HttpClientModule,
    OwlDateTimeModule,
    OwlNativeDateTimeModule,
    BrowserAnimationsModule,
    MatDialogModule,
    MatButtonModule,
    AppRoutingModule,
    NavigationBarDriverComponent
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

和我的NavigationBarDriverComponent看起来像这样:

import { Component, NgModule } from '@angular/core';
import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout';
import { Observable } from 'rxjs';
import { map, shareReplay } from 'rxjs/operators';

@Component({
  selector: 'app-navigation-bar-driver',
  templateUrl: './navigation-bar-driver.component.html',
  styleUrls: ['./navigation-bar-driver.component.css']
})

export class NavigationBarDriverComponent {

  drawer;

  isHandset$: Observable<boolean> = this.breakpointObserver.observe(Breakpoints.Handset)
    .pipe(
      map(result => result.matches),
      shareReplay()
    );

  constructor(private breakpointObserver: BreakpointObserver) {}

}

我尝试使用“ ng serve”和“ ng serve --prod”重新启动角度服务器,正如我在另一个线程中看到的那样。

1 个答案:

答案 0 :(得分:-1)

从应用模块导入中删除NavigationBarDriverComponent。