在angular2 es5中通过延迟加载找不到模块

时间:2016-12-20 12:19:29

标签: lazy-loading angular2-routing ecmascript-5

我在EcmaScript 5中使用Angular 2创建了一个应用程序。通过实现"延迟加载"我收到此错误消息:

无法找到' DetailModule'。

那是我的/src/app/app.module.js

var ngCore = require('@angular/core'),
    platformBrowser = require('@angular/platform-browser'),
    router = require('@angular/router');

var AppComponent = require('my-app/app/app.component.js');
var ListComponent = require('my-app/list/list.component.js');

var appRoutes = [
  { path: '', component: ListComponent },
  { path: 'detail', loadChildren: "detail/detail.module.js#DetailModule"}
];

MyAppModule = ngCore.NgModule({
  imports: [ 
    platformBrowser.BrowserModule,      
    router.RouterModule.forRoot(appRoutes)
  ],
  declarations: [ AppComponent, ListComponent ],
  bootstrap: [ AppComponent ]
}).Class({
  constructor: function (){
  }
});

module.exports = MyAppModule;

这是我的detail.module.js:

var ngCore = require('@angular/core'),
    router = require('@angular/router');

var ListComponent = require('my-app/list/list.component.js'),
    DetailComponent = require('my-app/detail/detail.component.js');

var routes = [
  { path: '', component: DetailComponent }
];

var routing = router.RouterModule.forChild(routes);

var module = ngCore.NgModule({
  imports: [ routing ],
  declarations: [ DetailComponent, ListComponent ]
}).Class({
  constructor: function (){
  }
});

module.exports = {
  DetailModule: module
};

如何使用ES5导出模块,以便angular2检测是?

0 个答案:

没有答案