简体   繁体   中英

Uncaught (in promise): Error: No NgModule metadata found for '[object Object]'

src/+login/index.ts

import { CommonModule } from '@angular/common';
import { NgModule }      from '@angular/core';
import { FormsModule }   from '@angular/forms';
import { HttpModule } from '@angular/http';
import { RouterModule } from '@angular/router';

import { LoginComponent } from './login.component';

export const routes=[
  { path:'',component:LoginComponent }
];
@NgModule({
  imports: [
    CommonModule,
    HttpModule,
    FormsModule,
    RouterModule.forChild(routes)
  ],
  declarations: [
    LoginComponent
  ],
})
export default class Login {
  static routes = routes;
}

src/app.routing.ts

import { Routes, RouterModule } from '@angular/router';

import { HomeComponent } from './home';

export const appRoutes: Routes = [
    { path:'',component:HomeComponent },
    { path:'login',loadChildren: ()=>System.import("./+login")}
];

error:

EXCEPTION: Uncaught (in promise): Error: No NgModule metadata found for '[object Object]'. ac_vendor<["./node_modules/@angular/compiler/src/ng_module_resolver.js"]/NgModuleResolverhttp://127.0.0.1:3000/vendor.bundle.js:13839:23

This problem plagued me for a long time, please help me

I had the same problem after upgrading from Angular 2.0.x to Angular 4.0.x Problem was in the syntax of Routes. You need to specify the NgModule that is responsible for display of child page.

Old syntax: { path: 'jobs', loadChildren: () => System.import('./jobs/jobs.module') }

New syntax: { path: 'jobs', loadChildren: 'app/pages/jobs/jobs.module#JobsModule' }

(note the #JobsModule at the end)

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