4

我正在创建一个 angular2 meteor 应用程序,我需要在其中进行延迟加载。

我已经尝试过 angular 2 doc 进行延迟加载。

应用程序.routes.ts

import { Route } from '@angular/router';
import { Meteor } from 'meteor/meteor';
import { LoginComponent } from './modules/loginComponent/login.component';
 export const routes: Route[] = [{
    path: '',
    redirectTo: "login",
    pathMatch: "full"
}, {
    path: 'login',
    component: LoginComponent
}, {
    path: 'csvtemplate',
    loadChildren: './modules/core/core.module#CoreModule'
}
];

核心路由.ts

const routes: Routes = [
  { path: '', component: TemplateComponent,
    children: [{
        path: '',
        redirectTo: 'csvtimeline'
    }, 
    {
        path: 'csvtimeline',
        component: CsvTimelineComponent
    }, {
        path: 'csvjson',
        component: CsvJsonComponent
    }, {
        path: 'addcategory',
        component: CsvAddProductComponent
    }, {
        path: 'adduser',
        component: adduserComponent
    }
    ]
}
];

当我在添加延迟加载后运行我的代码时,我收到了这个错误。

core.umd.js:3257 EXCEPTION: Uncaught (in promise): ReferenceError: System is not defined
ReferenceError: System is not defined
    at SystemJsNgModuleLoader.loadAndCompile (http://localhost:3000/packages/modules.js?hash=61f678ddc710f75692a22ec6b345330dc289d744:7882:20)
    at SystemJsNgModuleLoader.load (http://localhost:3000/packages/modules.js?hash=61f678ddc710f75692a22ec6b345330dc289d744:7875:64)
    at RouterConfigLoader.loadModuleFactory (http://localhost:3000/packages/modules.js?hash=61f678ddc710f75692a22ec6b345330dc289d744:18376:76)
    at RouterConfigLoader.load (http://localhost:3000/packages/modules.js?hash=61f678ddc710f75692a22ec6b345330dc289d744:18368:52)
    at MergeMapSubscriber.project (http://localhost:3000/packages/modules.js?hash=61f678ddc710f75692a22ec6b345330dc289d744:19111:82)
    at MergeMapSubscriber._tryNext (http://localhost:3000/packages/modules.js?hash=61f678ddc710f75692a22ec6b345330dc289d744:46645:27)
    at MergeMapSubscriber._next (http://localhost:3000/packages/modules.js?hash=61f678ddc710f75692a22ec6b345330dc289d744:46635:18)
    at MergeMapSubscriber.Subscriber.next (http://localhost:3000/packages/modules.js?hash=61f678ddc710f75692a22ec6b345330dc289d744:44167:18)
    at ScalarObservable._subscribe (http://localhost:3000/packages/modules.js?hash=61f678ddc710f75692a22ec6b345330dc289d744:54671:24)
    at ScalarObservable.Observable.subscribe (http://localhost:3000/packages/modules.js?hash=61f678ddc710f75692a22ec6b345330dc289d744:43030:27)

为什么它不工作。我应该怎么做才能让它工作?

谁能告诉我如何在 angular2-meteor 应用程序中使用延迟加载?

4

2 回答 2

2

我认为 Angular Meteor 现在支持延迟加载。这是如何做到这一点的代码

import {Route, RouterModule} from '@angular/router';
import {NgModule} from "@angular/core";
import {Home} from "../home/home.component";
import {CheapModule} from "../cheap/cheap.module";

declare global {
  interface NodeModule {
    dynamicImport(path: string): any;
  }
}

export const appRoutes: Route[] = [
  { path: '', component: Home },
  {
    path: 'cheap-route',
    loadChildren: () => CheapModule
  },
  {
    path: 'expensive-route',
    loadChildren: () => module.dynamicImport('../expensive/expensive.module').then(m => m.default)
  }
];

@NgModule({
  imports: [
    RouterModule.forRoot(appRoutes)
  ],
  exports: [
    RouterModule
  ]
})

export class AppRoutingModule {}

有关完整示例,请查看此 github 存储库https://github.com/joerex/angular-meteor-lazy-load

于 2017-06-16T05:40:18.313 回答
1

目前 angular-meteor 似乎不支持延迟加载。(参见:https ://github.com/Urigo/angular2-meteor/issues/370进行讨论)

于 2016-10-30T08:01:02.847 回答