类型“ EventViewerComponent”是2个模块的声明的一部分:Angular 7

时间:2019-04-11 05:38:05

标签: angular angular7

我正在angular 7中开发一个仪表板。当我在浏览器中启动我的应用程序时,它可以工作。但它返回此错误:

  

错误错误:未被捕获(承诺):错误:类型EventViewerComponent是以下两个模块的声明的一部分:LayoutModule和EventViewerModule!请考虑将EventViewerComponent移至导入LayoutModule和EventViewerModule的更高模块。您还可以创建一个新的NgModule,该导出并包含EventViewerComponent,然后在LayoutModule和EventViewerModule中导入该NgModule。

event-viewer.module.ts

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ChartsModule as Ng2Charts } from 'ng2-charts';

import { DataTablesModule } from 'angular-datatables';

import { EventRoutingModule } from './event-viewer-routing.module';
import { EventViewerComponent } from './event-viewer.component';
import { PageHeaderModule } from '../../shared';

@NgModule({
    imports: [CommonModule, Ng2Charts, EventRoutingModule, PageHeaderModule, DataTablesModule],
    declarations: [EventViewerComponent]
})
export class EventViewerModule {}

layout-routing.module.ts

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { LayoutComponent } from './layout.component';

const routes: Routes = [
    {
        path: '',
        component: LayoutComponent,
        children: [
            { path: '', redirectTo: 'dashboard', pathMatch: 'prefix' },
            { path: 'dashboard', loadChildren: './dashboard/dashboard.module#DashboardModule' },
            { path: 'charts', loadChildren: './charts/charts.module#ChartsModule' },
            { path: 'tables', loadChildren: './tables/tables.module#TablesModule' },
            { path: 'forms', loadChildren: './form/form.module#FormModule' },
            { path: 'bs-element', loadChildren: './bs-element/bs-element.module#BsElementModule' },
            { path: 'grid', loadChildren: './grid/grid.module#GridModule' },
            { path: 'components', loadChildren: './bs-component/bs-component.module#BsComponentModule' },
            { path: 'blank-page', loadChildren: './blank-page/blank-page.module#BlankPageModule' },
            { path: 'event-viewer', loadChildren: './event-viewer/event-viewer.module#EventViewerModule' }
            // { path: 'event-viewer', loadChildren: './' }
        ]
    }
];

@NgModule({
    imports: [RouterModule.forChild(routes)],
    exports: [RouterModule]
})
export class LayoutRoutingModule {}

event-viewer-routing.module.ts

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { EventViewerComponent } from './event-viewer.component';

const routes: Routes = [
    {
        path: '',
        component: EventViewerComponent
    }
];

@NgModule({
    imports: [RouterModule.forChild(routes)],
    exports: [RouterModule]
})
export class EventRoutingModule {}

似乎导入和声明混合了。但是我不知道应该在哪里添加导入和声明。

0 个答案:

没有答案