MCPcopy
hub / github.com/angular/angular / bootstrap

Function bootstrap

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

Source from the content-addressed store, hash-verified

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

Callers 2

Calls 15

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…