@@ -177,7 +177,8 @@ export function runPlatformInitializers(injector: Injector): void {
177177}
178178
179179/**
180- * Internal bootstrap application API that implements the core bootstrap logic.
180+ * Internal create application API that implements the core application creation logic and optional
181+ * bootstrap logic.
181182 *
182183 * Platforms (such as `platform-browser`) may require different set of application and platform
183184 * providers for an application to function correctly. As a result, platforms may use this function
@@ -186,17 +187,20 @@ export function runPlatformInitializers(injector: Injector): void {
186187 *
187188 * @returns A promise that returns an `ApplicationRef` instance once resolved.
188189 */
189- export function internalBootstrapApplication ( config : {
190- rootComponent : Type < unknown > ,
190+ export function internalCreateApplication ( config : {
191+ rootComponent ? : Type < unknown > ,
191192 appProviders ?: Array < Provider | ImportedNgModuleProviders > ,
192193 platformProviders ?: Provider [ ] ,
193194} ) : Promise < ApplicationRef > {
194195 const { rootComponent, appProviders, platformProviders} = config ;
195- NG_DEV_MODE && assertStandaloneComponentType ( rootComponent ) ;
196+
197+ if ( NG_DEV_MODE && rootComponent !== undefined ) {
198+ assertStandaloneComponentType ( rootComponent ) ;
199+ }
196200
197201 const platformInjector = createOrReusePlatformInjector ( platformProviders as StaticProvider [ ] ) ;
198202
199- const ngZone = new NgZone ( getNgZoneOptions ( ) ) ;
203+ const ngZone = getNgZone ( 'zone.js' , getNgZoneOptions ( ) ) ;
200204
201205 return ngZone . run ( ( ) => {
202206 // Create root application injector based on a set of providers configured at the platform
@@ -205,10 +209,11 @@ export function internalBootstrapApplication(config: {
205209 { provide : NgZone , useValue : ngZone } , //
206210 ...( appProviders || [ ] ) , //
207211 ] ;
208- const appInjector = createEnvironmentInjector (
212+
213+ const envInjector = createEnvironmentInjector (
209214 allAppProviders , platformInjector as EnvironmentInjector , 'Environment Injector' ) ;
210215
211- const exceptionHandler : ErrorHandler | null = appInjector . get ( ErrorHandler , null ) ;
216+ const exceptionHandler : ErrorHandler | null = envInjector . get ( ErrorHandler , null ) ;
212217 if ( NG_DEV_MODE && ! exceptionHandler ) {
213218 throw new RuntimeError (
214219 RuntimeErrorCode . ERROR_HANDLER_NOT_FOUND ,
@@ -223,27 +228,30 @@ export function internalBootstrapApplication(config: {
223228 }
224229 } ) ;
225230 } ) ;
231+
232+ // If the whole platform is destroyed, invoke the `destroy` method
233+ // for all bootstrapped applications as well.
234+ const destroyListener = ( ) => envInjector . destroy ( ) ;
235+ const onPlatformDestroyListeners = platformInjector . get ( PLATFORM_DESTROY_LISTENERS ) ;
236+ onPlatformDestroyListeners . add ( destroyListener ) ;
237+
238+ envInjector . onDestroy ( ( ) => {
239+ onErrorSubscription . unsubscribe ( ) ;
240+ onPlatformDestroyListeners . delete ( destroyListener ) ;
241+ } ) ;
242+
226243 return _callAndReportToErrorHandler ( exceptionHandler ! , ngZone , ( ) => {
227- const initStatus = appInjector . get ( ApplicationInitStatus ) ;
244+ const initStatus = envInjector . get ( ApplicationInitStatus ) ;
228245 initStatus . runInitializers ( ) ;
246+
229247 return initStatus . donePromise . then ( ( ) => {
230- const localeId = appInjector . get ( LOCALE_ID , DEFAULT_LOCALE_ID ) ;
248+ const localeId = envInjector . get ( LOCALE_ID , DEFAULT_LOCALE_ID ) ;
231249 setLocaleId ( localeId || DEFAULT_LOCALE_ID ) ;
232250
233- const appRef = appInjector . get ( ApplicationRef ) ;
234-
235- // If the whole platform is destroyed, invoke the `destroy` method
236- // for all bootstrapped applications as well.
237- const destroyListener = ( ) => appRef . destroy ( ) ;
238- const onPlatformDestroyListeners = platformInjector . get ( PLATFORM_DESTROY_LISTENERS , null ) ;
239- onPlatformDestroyListeners ?. add ( destroyListener ) ;
240-
241- appRef . onDestroy ( ( ) => {
242- onPlatformDestroyListeners ?. delete ( destroyListener ) ;
243- onErrorSubscription . unsubscribe ( ) ;
244- } ) ;
245-
246- appRef . bootstrap ( rootComponent ) ;
251+ const appRef = envInjector . get ( ApplicationRef ) ;
252+ if ( rootComponent !== undefined ) {
253+ appRef . bootstrap ( rootComponent ) ;
254+ }
247255 return appRef ;
248256 } ) ;
249257 } ) ;
@@ -493,7 +501,7 @@ export class PlatformRef {
493501 }
494502
495503 private _moduleDoBootstrap ( moduleRef : InternalNgModuleRef < any > ) : void {
496- const appRef = moduleRef . injector . get ( ApplicationRef ) as ApplicationRef ;
504+ const appRef = moduleRef . injector . get ( ApplicationRef ) ;
497505 if ( moduleRef . _bootstrapComponents . length > 0 ) {
498506 moduleRef . _bootstrapComponents . forEach ( f => appRef . bootstrap ( f ) ) ;
499507 } else if ( moduleRef . instance . ngDoBootstrap ) {
0 commit comments