【问题标题】:Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class出现在 AppModule 的 NgModule.imports 中,但无法解析为 NgModule 类
【发布时间】:2021-01-29 06:51:46
【问题描述】:

嗨, 我收到了上述问题。请帮助我解决如何解决此问题。 我已经按照这个error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class 进行了尝试。重新启动服务器并重新安装软件包(npm install),但错误仍然存​​在。

我的 navbar.component.ts 代码

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

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

  constructor() { }

  ngOnInit(): void {
  }

}

我的 navbar.component.html 代码

<nav class="navbar navbar-expand-lg navbar-dark bg-danger">
  
    <a class="navbar-brand" routerLink="#"><B>hn</B></a>
    
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarNavAltMarkup">
      <div class="navbar-nav">
        <a class="nav-item nav-link active" routerLink="HOME">HOME  <span class="sr-only">(current)</span></a>
        <a class="nav-item nav-link active" routerLink="ABOUT">ABOUT  <span class="sr-only">(current)</span></a>
        <a class="nav-item nav-link active" routerLink="CONTACT">CONTACT  <span class="sr-only">(current)</span></a>
        <a class="nav-item nav-link active" routerLink="ADDRESS">ADDRESS <span class="sr-only">(current)</span></a>
      </div>
    </div>
  </nav>

app.module.ts 代码

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { ChartsModule } from 'ng2-charts';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { RoutingModule } from './routing/routing.module';
import { MyPageComponent } from './my-page/my-page.component';
import { GridModule } from '@syncfusion/ej2-angular-grids';
import { NavbarComponent } from './navbar/navbar.component';
import {HttpClientModule} from '@angular/common/http';
import { DataService } from './dataservice';


@NgModule({
  declarations: [
    AppComponent,
    MyPageComponent,
    NavbarComponent,

  ],

  imports: [
    BrowserModule,FormsModule,ChartsModule,
    AppRoutingModule,
    RoutingModule,GridModule,NavbarComponent,HttpClientModule
  ],
  
  providers: [DataService],
  bootstrap: [AppComponent]
})
export class AppModule { }

mypage.component.ts 代码

import { Component, OnInit,ViewChild } from '@angular/core';
import { ChartDataSets, ChartOptions,ChartType } from 'chart.js';
import { Color, Label,SingleDataSet,monkeyPatchChartJsLegend,monkeyPatchChartJsTooltip } from 'ng2-charts';
import { DataService } from '../dataservice';
import { User } from '../User.module'; 
@Component({
  selector: 'app-my-page',
  templateUrl: './my-page.component.html',
  styleUrls: ['./my-page.component.css']
})
export class MyPageComponent implements OnInit {
public data: Object[];
  public lineChartData: ChartDataSets[] = [
    { data: [65, 59, 80, 81, 56, 55, 40], label: 'Series A' },
  ];
  public lineChartLabels: Label[] = ['January', 'February', 'March', 'April', 'May', 'June', 'July'];
  public lineChartOptions: any = {
    responsive: true,
  };
  public lineChartColors: Color[] = [
    {
      borderColor: 'black',
      backgroundColor: 'maroon',
    },
  ];
  public lineChartLegend = true;
  public lineChartType = 'line';
  public lineChartPlugins = [];

}

【问题讨论】:

  • Module中不需要导入“NavbarComponent”。

标签: html angular typescript


【解决方案1】:

NavbarComponent 组件应该在declarations 中列出,而不是在imports 中。

【讨论】:

    猜你喜欢
    • 2020-06-03
    • 2020-05-31
    • 2021-07-03
    • 2021-12-15
    • 1970-01-01
    • 1970-01-01
    • 2021-04-16
    • 1970-01-01
    • 2021-11-09
    相关资源
    最近更新 更多