MCPcopy
hub / github.com/angular/angular / downgradeModule

Function downgradeModule

packages/upgrade/static/src/downgrade_module.ts:373–452  ·  view source on GitHub ↗
(
  moduleOrBootstrapFn:
    | Type<T>
    | NgModuleFactory<T>
    | ((extraProviders: StaticProvider[]) => Promise<NgModuleRef<T>>),
)

Source from the content-addressed store, hash-verified

371 * @publicApi
372 */
373export 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)).

Callers 5

module.tsFile · 0.90
module.tsFile · 0.90
module.tsFile · 0.90
doDowngradeModuleFunction · 0.90

Calls 12

setTempInjectorRefFunction · 0.90
bootstrapFnFunction · 0.85
bootstrapModuleMethod · 0.80
isFunctionMethod · 0.80
configMethod · 0.65
factoryMethod · 0.65
constantMethod · 0.65
thenMethod · 0.65
getMethod · 0.65
onDestroyMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…