feat(module-loader): add preloadModules config option, set to false

set nav/basic to preload modules
This commit is contained in:
Brandy Carney
2017-03-07 12:04:04 -05:00
parent 759fe607c8
commit bdbd521b13
3 changed files with 9 additions and 6 deletions

View File

@@ -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' },

View File

@@ -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 },

View File

@@ -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);
}
}
};
}