@@ -22,7 +22,7 @@ import {
2222} from '../change_detection/scheduling/ng_zone_scheduling' ;
2323import {
2424 ChangeDetectionScheduler ,
25- ZONELESS_ENABLED ,
25+ PROVIDED_ZONELESS ,
2626} from '../change_detection/scheduling/zoneless_scheduling' ;
2727import { ChangeDetectionSchedulerImpl } from '../change_detection/scheduling/zoneless_scheduling_impl' ;
2828import { Injectable , InjectionToken , Injector } from '../di' ;
@@ -36,7 +36,7 @@ import {InternalNgModuleRef, NgModuleFactory, NgModuleRef} from '../linker/ng_mo
3636import { setLocaleId } from '../render3' ;
3737import { createNgModuleRefWithProviders } from '../render3/ng_module_ref' ;
3838import { stringify } from '../util/stringify' ;
39- import { getNgZone } from '../zone/ng_zone' ;
39+ import { getNgZone , NgZone , NoopNgZone } from '../zone/ng_zone' ;
4040
4141/**
4242 * Internal token that allows to register extra callbacks that should be invoked during the
@@ -76,54 +76,49 @@ export class PlatformRef {
7676 moduleFactory : NgModuleFactory < M > ,
7777 options ?: BootstrapOptions ,
7878 ) : Promise < NgModuleRef < M > > {
79- // Note: We need to create the NgZone _before_ we instantiate the module,
80- // as instantiating the module creates some providers eagerly.
81- // So we create a mini parent injector that just contains the new NgZone and
82- // pass that as parent to the NgModuleFactory.
83- const ngZone = getNgZone (
84- options ?. ngZone ,
85- getNgZoneOptions ( {
86- eventCoalescing : options ?. ngZoneEventCoalescing ,
87- runCoalescing : options ?. ngZoneRunCoalescing ,
79+ const ngZoneFactory = ( ) =>
80+ getNgZone (
81+ options ?. ngZone ,
82+ getNgZoneOptions ( {
83+ eventCoalescing : options ?. ngZoneEventCoalescing ,
84+ runCoalescing : options ?. ngZoneRunCoalescing ,
85+ } ) ,
86+ ) ;
87+ const ignoreChangesOutsideZone = options ?. ignoreChangesOutsideZone ;
88+ const allAppProviders = [
89+ internalProvideZoneChangeDetection ( {
90+ ngZoneFactory,
91+ ignoreChangesOutsideZone,
8892 } ) ,
93+ { provide : ChangeDetectionScheduler , useExisting : ChangeDetectionSchedulerImpl } ,
94+ ] ;
95+ const moduleRef = createNgModuleRefWithProviders (
96+ moduleFactory . moduleType ,
97+ this . injector ,
98+ allAppProviders ,
8999 ) ;
90- // Note: Create ngZoneInjector within ngZone.run so that all of the instantiated services are
91- // created within the Angular zone
92- // Do not try to replace ngZone.run with ApplicationRef#run because ApplicationRef would then be
93- // created outside of the Angular zone.
94- return ngZone . run ( ( ) => {
95- const ignoreChangesOutsideZone = options ?. ignoreChangesOutsideZone ;
96- const moduleRef = createNgModuleRefWithProviders ( moduleFactory . moduleType , this . injector , [
97- ...internalProvideZoneChangeDetection ( {
98- ngZoneFactory : ( ) => ngZone ,
99- ignoreChangesOutsideZone,
100- } ) ,
101- { provide : ChangeDetectionScheduler , useExisting : ChangeDetectionSchedulerImpl } ,
102- ] ) ;
100+ const envInjector = moduleRef . injector ;
101+ const ngZone = envInjector . get ( NgZone ) ;
103102
103+ return ngZone . run ( ( ) => {
104+ moduleRef . resolveInjectorInitializers ( ) ;
105+ const exceptionHandler = envInjector . get ( ErrorHandler , null ) ;
104106 if ( typeof ngDevMode === 'undefined' || ngDevMode ) {
105- if ( moduleRef . injector . get ( PROVIDED_NG_ZONE ) ) {
107+ if ( exceptionHandler === null ) {
106108 throw new RuntimeError (
107- RuntimeErrorCode . PROVIDER_IN_WRONG_CONTEXT ,
108- '`bootstrapModule` does not support `provideZoneChangeDetection`. Use `BootstrapOptions` instead. ' ,
109+ RuntimeErrorCode . MISSING_REQUIRED_INJECTABLE_IN_BOOTSTRAP ,
110+ 'No ErrorHandler. Is platform module (BrowserModule) included? ' ,
109111 ) ;
110112 }
111- if ( moduleRef . injector . get ( ZONELESS_ENABLED ) && options ?. ngZone !== 'noop' ) {
113+ if ( envInjector . get ( PROVIDED_ZONELESS ) && envInjector . get ( PROVIDED_NG_ZONE ) ) {
112114 throw new RuntimeError (
113115 RuntimeErrorCode . PROVIDED_BOTH_ZONE_AND_ZONELESS ,
114116 'Invalid change detection configuration: ' +
115- "`ngZone: 'noop'` must be set in `BootstrapOptions` with provideExperimentalZonelessChangeDetection." ,
117+ 'provideZoneChangeDetection and provideExperimentalZonelessChangeDetection cannot be used together.' ,
116118 ) ;
117119 }
118120 }
119121
120- const exceptionHandler = moduleRef . injector . get ( ErrorHandler , null ) ;
121- if ( ( typeof ngDevMode === 'undefined' || ngDevMode ) && exceptionHandler === null ) {
122- throw new RuntimeError (
123- RuntimeErrorCode . MISSING_REQUIRED_INJECTABLE_IN_BOOTSTRAP ,
124- 'No ErrorHandler. Is platform module (BrowserModule) included?' ,
125- ) ;
126- }
127122 ngZone . runOutsideAngular ( ( ) => {
128123 const subscription = ngZone . onError . subscribe ( {
129124 next : ( error : any ) => {
@@ -136,11 +131,12 @@ export class PlatformRef {
136131 } ) ;
137132 } ) ;
138133 return _callAndReportToErrorHandler ( exceptionHandler ! , ngZone , ( ) => {
139- const initStatus : ApplicationInitStatus = moduleRef . injector . get ( ApplicationInitStatus ) ;
134+ const initStatus = envInjector . get ( ApplicationInitStatus ) ;
140135 initStatus . runInitializers ( ) ;
136+
141137 return initStatus . donePromise . then ( ( ) => {
142138 // If the `LOCALE_ID` provider is defined at bootstrap then we set the value for ivy
143- const localeId = moduleRef . injector . get ( LOCALE_ID , DEFAULT_LOCALE_ID ) ;
139+ const localeId = envInjector . get ( LOCALE_ID , DEFAULT_LOCALE_ID ) ;
144140 setLocaleId ( localeId || DEFAULT_LOCALE_ID ) ;
145141 this . _moduleDoBootstrap ( moduleRef ) ;
146142 return moduleRef ;
0 commit comments