|
1 | | -import { NgModuleRef, Injector, NgModuleFactory, Type, Compiler } from '@angular/core'; |
| 1 | +import { NgModuleRef, Injector, Type, createNgModule } from '@angular/core'; |
2 | 2 | import { |
3 | 3 | Transition, |
4 | 4 | LazyLoadResult, |
5 | 5 | UIRouter, |
6 | 6 | Resolvable, |
7 | 7 | NATIVE_INJECTOR_TOKEN, |
8 | | - isString, |
9 | 8 | unnestR, |
10 | 9 | inArray, |
11 | 10 | StateObject, |
@@ -72,42 +71,16 @@ export function loadNgModule( |
72 | 71 | ): (transition: Transition, stateObject: StateDeclaration) => Promise<LazyLoadResult> { |
73 | 72 | return (transition: Transition, stateObject: StateDeclaration) => { |
74 | 73 | const ng2Injector = transition.injector().get(NATIVE_INJECTOR_TOKEN); |
75 | | - |
76 | | - const createModule = (factory: NgModuleFactory<any>) => factory.create(ng2Injector); |
77 | | - |
| 74 | + const unwrapEsModuleDefault = x => (x && x.__esModule && x['default'] ? x['default'] : x); |
78 | 75 | const applyModule = (moduleRef: NgModuleRef<any>) => applyNgModule(transition, moduleRef, ng2Injector, stateObject); |
79 | 76 |
|
80 | | - return loadModuleFactory(moduleToLoad, ng2Injector).then(createModule).then(applyModule); |
| 77 | + return Promise.resolve(moduleToLoad()) |
| 78 | + .then(unwrapEsModuleDefault) |
| 79 | + .then((ngModule: Type<any>) => createNgModule(ngModule, ng2Injector)) |
| 80 | + .then(applyModule); |
81 | 81 | }; |
82 | 82 | } |
83 | 83 |
|
84 | | -/** |
85 | | - * Returns the module factory that can be used to instantiate a module |
86 | | - * |
87 | | - * For a Type<any> or Promise<Type<any>> this: |
88 | | - * - Compiles the component type (if not running with AOT) |
89 | | - * - Returns the NgModuleFactory resulting from compilation (or direct loading if using AOT) as a Promise |
90 | | - * |
91 | | - * @internal |
92 | | - */ |
93 | | -export function loadModuleFactory( |
94 | | - moduleToLoad: ModuleTypeCallback, |
95 | | - ng2Injector: Injector |
96 | | -): Promise<NgModuleFactory<any>> { |
97 | | - const compiler: Compiler = ng2Injector.get(Compiler); |
98 | | - |
99 | | - const unwrapEsModuleDefault = (x) => (x && x.__esModule && x['default'] ? x['default'] : x); |
100 | | - |
101 | | - return Promise.resolve(moduleToLoad()) |
102 | | - .then(unwrapEsModuleDefault) |
103 | | - .then((t: NgModuleFactory<any> | Type<any>) => { |
104 | | - if (t instanceof NgModuleFactory) { |
105 | | - return t; |
106 | | - } |
107 | | - return compiler.compileModuleAsync(t); |
108 | | - }); |
109 | | -} |
110 | | - |
111 | 84 | /** |
112 | 85 | * Apply the UI-Router Modules found in the lazy loaded module. |
113 | 86 | * |
|
0 commit comments