@@ -216,76 +216,80 @@ export function internalCreateApplication(config: {
216216 appProviders ?: Array < Provider | EnvironmentProviders > ,
217217 platformProviders ?: Provider [ ] ,
218218} ) : Promise < ApplicationRef > {
219- const { rootComponent, appProviders, platformProviders} = config ;
220-
221- if ( ( typeof ngDevMode === 'undefined' || ngDevMode ) && rootComponent !== undefined ) {
222- assertStandaloneComponentType ( rootComponent ) ;
223- }
219+ try {
220+ const { rootComponent, appProviders, platformProviders} = config ;
224221
225- const platformInjector = createOrReusePlatformInjector ( platformProviders as StaticProvider [ ] ) ;
222+ if ( ( typeof ngDevMode === 'undefined' || ngDevMode ) && rootComponent !== undefined ) {
223+ assertStandaloneComponentType ( rootComponent ) ;
224+ }
226225
227- // Create root application injector based on a set of providers configured at the platform
228- // bootstrap level as well as providers passed to the bootstrap call by a user.
229- const allAppProviders = [
230- provideZoneChangeDetection ( ) ,
231- ...( appProviders || [ ] ) ,
232- ] ;
233- const adapter = new EnvironmentNgModuleRefAdapter ( {
234- providers : allAppProviders ,
235- parent : platformInjector as EnvironmentInjector ,
236- debugName : ( typeof ngDevMode === 'undefined' || ngDevMode ) ? 'Environment Injector' : '' ,
237- // We skip environment initializers because we need to run them inside the NgZone, which happens
238- // after we get the NgZone instance from the Injector.
239- runEnvironmentInitializers : false ,
240- } ) ;
241- const envInjector = adapter . injector ;
242- const ngZone = envInjector . get ( NgZone ) ;
226+ const platformInjector = createOrReusePlatformInjector ( platformProviders as StaticProvider [ ] ) ;
227+
228+ // Create root application injector based on a set of providers configured at the platform
229+ // bootstrap level as well as providers passed to the bootstrap call by a user.
230+ const allAppProviders = [
231+ provideZoneChangeDetection ( ) ,
232+ ...( appProviders || [ ] ) ,
233+ ] ;
234+ const adapter = new EnvironmentNgModuleRefAdapter ( {
235+ providers : allAppProviders ,
236+ parent : platformInjector as EnvironmentInjector ,
237+ debugName : ( typeof ngDevMode === 'undefined' || ngDevMode ) ? 'Environment Injector' : '' ,
238+ // We skip environment initializers because we need to run them inside the NgZone, which
239+ // happens after we get the NgZone instance from the Injector.
240+ runEnvironmentInitializers : false ,
241+ } ) ;
242+ const envInjector = adapter . injector ;
243+ const ngZone = envInjector . get ( NgZone ) ;
243244
244- return ngZone . run ( ( ) => {
245- envInjector . resolveInjectorInitializers ( ) ;
246- const exceptionHandler : ErrorHandler | null = envInjector . get ( ErrorHandler , null ) ;
247- if ( ( typeof ngDevMode === 'undefined' || ngDevMode ) && ! exceptionHandler ) {
248- throw new RuntimeError (
249- RuntimeErrorCode . MISSING_REQUIRED_INJECTABLE_IN_BOOTSTRAP ,
250- 'No `ErrorHandler` found in the Dependency Injection tree.' ) ;
251- }
245+ return ngZone . run ( ( ) => {
246+ envInjector . resolveInjectorInitializers ( ) ;
247+ const exceptionHandler : ErrorHandler | null = envInjector . get ( ErrorHandler , null ) ;
248+ if ( ( typeof ngDevMode === 'undefined' || ngDevMode ) && ! exceptionHandler ) {
249+ throw new RuntimeError (
250+ RuntimeErrorCode . MISSING_REQUIRED_INJECTABLE_IN_BOOTSTRAP ,
251+ 'No `ErrorHandler` found in the Dependency Injection tree.' ) ;
252+ }
252253
253- let onErrorSubscription : Subscription ;
254- ngZone . runOutsideAngular ( ( ) => {
255- onErrorSubscription = ngZone . onError . subscribe ( {
256- next : ( error : any ) => {
257- exceptionHandler ! . handleError ( error ) ;
258- }
254+ let onErrorSubscription : Subscription ;
255+ ngZone . runOutsideAngular ( ( ) => {
256+ onErrorSubscription = ngZone . onError . subscribe ( {
257+ next : ( error : any ) => {
258+ exceptionHandler ! . handleError ( error ) ;
259+ }
260+ } ) ;
259261 } ) ;
260- } ) ;
261262
262- // If the whole platform is destroyed, invoke the `destroy` method
263- // for all bootstrapped applications as well.
264- const destroyListener = ( ) => envInjector . destroy ( ) ;
265- const onPlatformDestroyListeners = platformInjector . get ( PLATFORM_DESTROY_LISTENERS ) ;
266- onPlatformDestroyListeners . add ( destroyListener ) ;
263+ // If the whole platform is destroyed, invoke the `destroy` method
264+ // for all bootstrapped applications as well.
265+ const destroyListener = ( ) => envInjector . destroy ( ) ;
266+ const onPlatformDestroyListeners = platformInjector . get ( PLATFORM_DESTROY_LISTENERS ) ;
267+ onPlatformDestroyListeners . add ( destroyListener ) ;
267268
268- envInjector . onDestroy ( ( ) => {
269- onErrorSubscription . unsubscribe ( ) ;
270- onPlatformDestroyListeners . delete ( destroyListener ) ;
271- } ) ;
269+ envInjector . onDestroy ( ( ) => {
270+ onErrorSubscription . unsubscribe ( ) ;
271+ onPlatformDestroyListeners . delete ( destroyListener ) ;
272+ } ) ;
272273
273- return _callAndReportToErrorHandler ( exceptionHandler ! , ngZone , ( ) => {
274- const initStatus = envInjector . get ( ApplicationInitStatus ) ;
275- initStatus . runInitializers ( ) ;
274+ return _callAndReportToErrorHandler ( exceptionHandler ! , ngZone , ( ) => {
275+ const initStatus = envInjector . get ( ApplicationInitStatus ) ;
276+ initStatus . runInitializers ( ) ;
276277
277- return initStatus . donePromise . then ( ( ) => {
278- const localeId = envInjector . get ( LOCALE_ID , DEFAULT_LOCALE_ID ) ;
279- setLocaleId ( localeId || DEFAULT_LOCALE_ID ) ;
278+ return initStatus . donePromise . then ( ( ) => {
279+ const localeId = envInjector . get ( LOCALE_ID , DEFAULT_LOCALE_ID ) ;
280+ setLocaleId ( localeId || DEFAULT_LOCALE_ID ) ;
280281
281- const appRef = envInjector . get ( ApplicationRef ) ;
282- if ( rootComponent !== undefined ) {
283- appRef . bootstrap ( rootComponent ) ;
284- }
285- return appRef ;
282+ const appRef = envInjector . get ( ApplicationRef ) ;
283+ if ( rootComponent !== undefined ) {
284+ appRef . bootstrap ( rootComponent ) ;
285+ }
286+ return appRef ;
287+ } ) ;
286288 } ) ;
287289 } ) ;
288- } ) ;
290+ } catch ( e ) {
291+ return Promise . reject ( e ) ;
292+ }
289293}
290294
291295/**
0 commit comments