简体   繁体   中英

Error: No NgModule metadata found for 'module'

I am new to angular2, i want to put multiple component in one routing.module.ts and multiple module in one module.ts.But i got an error Error: No NgModule metadata found for 'JobfileModule'. I have searh for any possible solution but i still cannot solve it and still confused with my style of code.

this is my code

routing.module.ts

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { JobComponent } from './job.component';
import { JobfileComponent } from './jobfile.component';

const routes: Routes = [
  {
    path: '',
    component: JobComponent, data: {
      title: 'Job' }
  },
  {
    path: '',
    component: JobfileComponent, data: {
      title: 'JobFile' }
  }
];

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule]

})
export class JobRoutingModule {}

and my module.ts

import { NgModule } from '@angular/core';
import { ChartsModule } from 'ng2-charts/ng2-charts';
import { JobComponent } from './job.component';
import { JobfileComponent } from './jobfile.component';
import { JobRoutingModule } from './job-routing.module';

@NgModule({
  imports: [
    JobRoutingModule,
    ChartsModule
  ],
  declarations: [ JobComponent, JobfileComponent  ]
})
export class JobModule { }
export class JobfileModule { }

What is wrong with my code?

you need to decleare your component at your JobRoutingModule and not your app module.

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule],
  declarations: [ JobComponent, JobfileComponent  ]
})
export class JobRoutingModule {}

and remove export class JobModule { } you not use it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM