From bdbd521b1326fcd18dd9b2831aac5f0e69064ba0 Mon Sep 17 00:00:00 2001 From: Brandy Carney Date: Tue, 7 Mar 2017 12:04:04 -0500 Subject: [PATCH] feat(module-loader): add preloadModules config option, set to false set nav/basic to preload modules --- src/components/nav/test/basic/app/app.module.ts | 2 +- src/index.ts | 2 +- src/util/module-loader.ts | 11 +++++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/components/nav/test/basic/app/app.module.ts b/src/components/nav/test/basic/app/app.module.ts index edf18280a2..efd0b66da1 100644 --- a/src/components/nav/test/basic/app/app.module.ts +++ b/src/components/nav/test/basic/app/app.module.ts @@ -17,7 +17,7 @@ import { MyCmpTest2 } from '../pages/first-page/my-component-two'; ], imports: [ BrowserModule, - IonicModule.forRoot(E2EApp, { swipeBackEnabled: true }, { + IonicModule.forRoot(E2EApp, { swipeBackEnabled: true, preloadModules: true }, { links: [ { name: 'first-page', component: FirstPage }, { name: 'another-page', loadChildren: '../pages/another-page/another-page.module#AnotherPageModule' }, diff --git a/src/index.ts b/src/index.ts index 09ed270b9c..886adc2066 100644 --- a/src/index.ts +++ b/src/index.ts @@ -591,7 +591,7 @@ export class IonicModule { { provide: APP_INITIALIZER, useFactory: registerModeConfigs, deps: [ Config ], multi: true }, { provide: APP_INITIALIZER, useFactory: setupProvideEvents, deps: [ Platform, DomController ], multi: true }, { provide: APP_INITIALIZER, useFactory: setupTapClick, deps: [ Config, Platform, DomController, App, NgZone, GestureController ], multi: true }, - { provide: APP_INITIALIZER, useFactory: setupPreloading, deps: [ DeepLinkConfigToken, ModuleLoader ], multi: true }, + { provide: APP_INITIALIZER, useFactory: setupPreloading, deps: [ Config, DeepLinkConfigToken, ModuleLoader ], multi: true }, // useClass // { provide: HAMMER_GESTURE_CONFIG, useClass: IonicGestureConfig }, diff --git a/src/util/module-loader.ts b/src/util/module-loader.ts index 99436fe59b..754a20cca1 100644 --- a/src/util/module-loader.ts +++ b/src/util/module-loader.ts @@ -1,4 +1,5 @@ import { ComponentFactoryResolver, Injectable, Injector, NgModuleFactory, OpaqueToken, Type } from '@angular/core'; +import { Config } from '../config/config'; import { DeepLinkConfig } from '../navigation/nav-util'; import { NgModuleLoader } from './ng-module-loader'; @@ -75,11 +76,13 @@ export interface LoadedModule { /** * @private */ -export function setupPreloading(deepLinkConfig: DeepLinkConfig, moduleLoader: ModuleLoader) { +export function setupPreloading(config: Config, deepLinkConfig: DeepLinkConfig, moduleLoader: ModuleLoader) { return function() { - const linksToLoad = deepLinkConfig.links.filter(link => !!link.loadChildren); - for (const link of linksToLoad) { - moduleLoader.load(link.loadChildren); + if (config.getBoolean('preloadModules')) { + const linksToLoad = deepLinkConfig.links.filter(link => !!link.loadChildren); + for (const link of linksToLoad) { + moduleLoader.load(link.loadChildren); + } } }; }