(
moduleOrBootstrapFn:
| Type<T>
| NgModuleFactory<T>
| ((extraProviders: StaticProvider[]) => Promise<NgModuleRef<T>>),
)
| 371 | * @publicApi |
| 372 | */ |
| 373 | export function downgradeModule<T>( |
| 374 | moduleOrBootstrapFn: |
| 375 | | Type<T> |
| 376 | | NgModuleFactory<T> |
| 377 | | ((extraProviders: StaticProvider[]) => Promise<NgModuleRef<T>>), |
| 378 | ): string { |
| 379 | const lazyModuleName = `${ɵconstants.UPGRADE_MODULE_NAME}.lazy${++moduleUid}`; |
| 380 | const lazyModuleRefKey = `${ɵconstants.LAZY_MODULE_REF}${lazyModuleName}`; |
| 381 | const lazyInjectorKey = `${ɵconstants.INJECTOR_KEY}${lazyModuleName}`; |
| 382 | |
| 383 | let bootstrapFn: (extraProviders: StaticProvider[]) => Promise<NgModuleRef<T>>; |
| 384 | if (ɵutil.isNgModuleType(moduleOrBootstrapFn)) { |
| 385 | // NgModule class |
| 386 | bootstrapFn = (extraProviders: StaticProvider[]) => |
| 387 | platformBrowser(extraProviders).bootstrapModule(moduleOrBootstrapFn, { |
| 388 | applicationProviders: [internalProvideZoneChangeDetection({})], |
| 389 | }); |
| 390 | } else if (!ɵutil.isFunction(moduleOrBootstrapFn)) { |
| 391 | // NgModule factory |
| 392 | bootstrapFn = (extraProviders: StaticProvider[]) => |
| 393 | platformBrowser(extraProviders).bootstrapModuleFactory(moduleOrBootstrapFn, { |
| 394 | applicationProviders: [internalProvideZoneChangeDetection({})], |
| 395 | }); |
| 396 | } else { |
| 397 | // bootstrap function |
| 398 | bootstrapFn = moduleOrBootstrapFn; |
| 399 | } |
| 400 | |
| 401 | let injector: Injector; |
| 402 | |
| 403 | // Create an ng1 module to bootstrap. |
| 404 | ɵangular1 |
| 405 | .module_(lazyModuleName, []) |
| 406 | .constant(ɵconstants.UPGRADE_APP_TYPE_KEY, ɵutil.UpgradeAppType.Lite) |
| 407 | .factory(ɵconstants.INJECTOR_KEY, [lazyInjectorKey, identity]) |
| 408 | .factory(lazyInjectorKey, () => { |
| 409 | if (!injector) { |
| 410 | throw new Error( |
| 411 | 'Trying to get the Angular injector before bootstrapping the corresponding ' + |
| 412 | 'Angular module.', |
| 413 | ); |
| 414 | } |
| 415 | return injector; |
| 416 | }) |
| 417 | .factory(ɵconstants.LAZY_MODULE_REF, [lazyModuleRefKey, identity]) |
| 418 | .factory(lazyModuleRefKey, [ |
| 419 | ɵconstants.$INJECTOR, |
| 420 | ($injector: ɵangular1.IInjectorService) => { |
| 421 | setTempInjectorRef($injector); |
| 422 | const result: ɵutil.LazyModuleRef = { |
| 423 | promise: bootstrapFn(angular1Providers).then((ref) => { |
| 424 | injector = result.injector = new NgAdapterInjector(ref.injector); |
| 425 | injector.get(ɵconstants.$INJECTOR); |
| 426 | |
| 427 | // Destroy the AngularJS app once the Angular `PlatformRef` is destroyed. |
| 428 | // This does not happen in a typical SPA scenario, but it might be useful for |
| 429 | // other use-cases where disposing of an Angular/AngularJS app is necessary |
| 430 | // (such as Hot Module Replacement (HMR)). |
no test coverage detected
searching dependent graphs…