[英]my question is, Unexpected directive 'BarChartComponent' imported by the module 'DashboardModule'. Please add a @NgModule annotation
I'm getting an error while compiling the code as编译代码时出现错误
Unexpected directive 'BarChartComponent' imported by the module 'DashboardModule'.
由模块“DashboardModule”导入的意外指令“BarChartComponent”。 Please add a @NgModule annotation.
请添加@NgModule 注释。
dashboard.module.ts
import { NgModule } from "@angular/core";
import { CommonModule } from "@angular/common";
import { RouterModule } from "@angular/router";
import { ModuleWithProviders } from "@angular/core";
import { DashboardComponent } from "./dashboard.component";
import { SharedModule } from "../shared";
import { ChartsService } from "../shared/chart.service";
import {BarChartComponent} from "../bar-chart/bar-chart.component";
const dashboardRouting: ModuleWithProviders = RouterModule.forChild([
{
path: "",
component: DashboardComponent
}
]);
@NgModule({
imports: [CommonModule, dashboardRouting, SharedModule, BarChartComponent],
declarations: [DashboardComponent],
providers: [ChartsService],
})
export class DashboardModule {}
The issue is with import of BarChartComponent
into imports array.问题在于将
BarChartComponent
导入到导入数组中。 You must declare the BarChartComponent
instead.您必须改为声明
BarChartComponent
。 As of now Angular is treating BarChartComponent
as Module.截至目前,Angular 将
BarChartComponent
视为模块。
It should be as -它应该是——
@NgModule({
imports: [CommonModule, dashboardRouting, SharedModul],
declarations: [DashboardComponent, BarChartComponent], //<-- move here
providers: [ChartsService],
})
export class DashboardModule {}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.