嗨, 我收到上述问题。请帮助我解决如何解决此问题。 我已经按照此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 = [];
}
答案 0 :(得分:1)
NavbarComponent
组件应在declarations
中列出,而不要在imports
中列出。