( config: ModuleBootstrapConfig<M> | ApplicationBootstrapConfig, )
| 76 | applicationBootstrapConfig: ApplicationBootstrapConfig, |
| 77 | ): Promise<ApplicationRef>; |
| 78 | export 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) { |
no test coverage detected