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