MCPcopy Create free account
hub / github.com/angular/angular / bootstrap

Function bootstrap

packages/core/src/platform/bootstrap.ts:78–187  ·  view source on GitHub ↗
(
  config: ModuleBootstrapConfig<M> | ApplicationBootstrapConfig,
)

Source from the content-addressed store, hash-verified

76 applicationBootstrapConfig: ApplicationBootstrapConfig,
77): Promise<ApplicationRef>;
78export function bootstrap<M>(
79 config: ModuleBootstrapConfig<M> | ApplicationBootstrapConfig,
80): Promise<ApplicationRef> | Promise<NgModuleRef<M>> {
81 const envInjector = isApplicationBootstrapConfig(config)
82 ? config.r3Injector
83 : config.moduleRef.injector;
84 const ngZone = envInjector.get(NgZone);
85 return ngZone.run(() => {
86 if (isApplicationBootstrapConfig(config)) {
87 config.r3Injector.resolveInjectorInitializers();
88 } else {
89 config.moduleRef.resolveInjectorInitializers();
90 }
91 const exceptionHandler = envInjector.get(INTERNAL_APPLICATION_ERROR_HANDLER);
92 if (typeof ngDevMode === 'undefined' || ngDevMode) {
93 if (envInjector.get(PROVIDED_ZONELESS) && envInjector.get(PROVIDED_NG_ZONE)) {
94 console.warn(
95 formatRuntimeError(
96 RuntimeErrorCode.PROVIDED_BOTH_ZONE_AND_ZONELESS,
97 'Both provideZoneChangeDetection and provideZonelessChangeDetection are provided. ' +
98 'This is likely a mistake. Update the application providers to use only one of the two.',
99 ),
100 );
101 }
102 }
103
104 let onErrorSubscription: Subscription;
105 ngZone.runOutsideAngular(() => {
106 onErrorSubscription = ngZone.onError.subscribe({
107 next: exceptionHandler,
108 });
109 });
110
111 // If the whole platform is destroyed, invoke the `destroy` method
112 // for all bootstrapped applications as well.
113 if (isApplicationBootstrapConfig(config)) {
114 const destroyListener = () => envInjector.destroy();
115 const onPlatformDestroyListeners = config.platformInjector.get(PLATFORM_DESTROY_LISTENERS);
116 onPlatformDestroyListeners.add(destroyListener);
117
118 envInjector.onDestroy(() => {
119 onErrorSubscription.unsubscribe();
120 onPlatformDestroyListeners.delete(destroyListener);
121 });
122 } else {
123 const destroyListener = () => config.moduleRef.destroy();
124 const onPlatformDestroyListeners = config.platformInjector.get(PLATFORM_DESTROY_LISTENERS);
125 onPlatformDestroyListeners.add(destroyListener);
126
127 config.moduleRef.onDestroy(() => {
128 remove(config.allPlatformModules, config.moduleRef);
129 onErrorSubscription.unsubscribe();
130 onPlatformDestroyListeners.delete(destroyListener);
131 });
132 }
133
134 const completeBootstrap = (onBootstrap: () => void, onSkipBootstrap?: () => void): void => {
135 if (envInjector.destroyed) {

Callers 2

Calls 15

formatRuntimeErrorFunction · 0.90
removeFunction · 0.90
completeBootstrapFunction · 0.85
runInitializersMethod · 0.80
finallyMethod · 0.80
getMethod · 0.65
runMethod · 0.65
warnMethod · 0.65
subscribeMethod · 0.65

Tested by

no test coverage detected