1

src/+登录/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")}
];

错误:

例外:未捕获(承诺):错误:未找到“[object Object]”的 NgModule 元数据。ac_vendor<["./node_modules/@angular/compiler/src/ng_module_resolver.js"]/NgModuleResolverhttp://127.0.0.1:3000/vendor.bundle.js:13839:23

这个问题困扰了我很久,求大神帮忙

4

1 回答 1

2

从 Angular 2.0.x 升级到 Angular 4.0.x 后我遇到了同样的问题 问题出在 Routes 的语法中。您需要指定负责显示子页面的 NgModule。

旧语法: { path: 'jobs', loadChildren: () => System.import('./jobs/jobs.module') }

新语法: { path: 'jobs', loadChildren: 'app/pages/jobs/jobs.module#JobsModule' }

(注意最后的#JobsModule

于 2017-04-27T07:14:32.167 回答