简体   繁体   English

我的问题是,模块“DashboardModule”导入的意外指令“BarChartComponent”。 请添加@NgModule 注释

[英]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.

相关问题 如何修复错误:由模块“DashboardModule”导入的意外值“DataTableModule”。 请添加@NgModule 注释 - How to fix Error: Unexpected value 'DataTableModule' imported by the module 'DashboardModule'. Please add a @NgModule annotation 由模块'AppModule'导入的意外指令'LoginComponent'。请添加@NgModule注释 - Unexpected directive 'LoginComponent' imported by the module 'AppModule'. Please add a @NgModule annotation 模块“AppModule”导入的意外指令“MatAutoCompleteTrigger”。 请添加@NgModule 注释 - Unexpected directive 'MatAutoCompleteTrigger' imported by the module 'AppModule'. Please add a @NgModule annotation 由模块&#39;AppModule&#39;导入的意外指令&#39;MatSpinner&#39;。 请添加@NgModule注释 - Unexpected directive 'MatSpinner' imported by the module 'AppModule'. Please add a @NgModule annotation 模块导入的意外指令请添加@ngmodule注释 - unexpected directive imported by the module please add a @ngmodule annotation 模块“DynamicTestModule”导入的意外指令“InformationComponent”。 请添加@NgModule 注解 - Unexpected directive 'InformationComponent' imported by the module 'DynamicTestModule'. Please add a @NgModule annotation 由模块&#39;AppModule&#39;导入的意外指令&#39;LoginPage&#39;。 请添加@NgModule注释 - Unexpected directive 'LoginPage' imported by the module 'AppModule'. Please add a @NgModule annotation 未捕获的错误:模块“MyMaterialModule”导入的意外指令“angular-material”。 请添加@NgModule 注释。 角 5 - Uncaught Error: Unexpected directive 'angular-material' imported by the module 'MyMaterialModule'. Please add a @NgModule annotation. angular 5 未捕获的错误:模块&#39;AppModule&#39;导入了意外的指令&#39;ProductsComponent&#39;。 请添加@NgModule批注 - Uncaught Error: Unexpected directive 'ProductsComponent' imported by the module 'AppModule'. Please add a @NgModule annotation 错误:模块“ SharedModule”导入了意外的指令“ DashboardPage”。 请添加@NgModule批注 - Error: Unexpected directive 'DashboardPage' imported by the module 'SharedModule'. Please add a @NgModule annotation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM