Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export function internalProvideZoneChangeDetection({
ngZoneFactory ??= () =>
new NgZone({...getNgZoneOptions(), scheduleInRootZone} as InternalNgZoneOptions);
return [
{provide: ZONELESS_ENABLED, useValue: false},
{provide: NgZone, useFactory: ngZoneFactory},
{
provide: ENVIRONMENT_INITIALIZER,
Expand Down Expand Up @@ -164,11 +165,7 @@ export function provideZoneChangeDetection(options?: NgZoneOptions): Environment
},
scheduleInRootZone,
});
return makeEnvironmentProviders([
{provide: PROVIDED_NG_ZONE, useValue: true},
{provide: ZONELESS_ENABLED, useValue: false},
zoneProviders,
]);
return makeEnvironmentProviders([{provide: PROVIDED_NG_ZONE, useValue: true}, zoneProviders]);
}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/core_private_export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,4 @@ export {TimerScheduler as ɵTimerScheduler} from './defer/timer_scheduler';
export {ɵassertType} from './type_checking';
export {ANIMATIONS_DISABLED as ɵANIMATIONS_DISABLED} from './animation/interfaces';
export {allLeavingAnimations as ɵallLeavingAnimations} from './animation/longest_animation';
export {setZoneProvidersForNextBootstrap as ɵsetZoneProvidersForNextBootstrap} from './platform/platform_ref';
14 changes: 12 additions & 2 deletions packages/core/src/platform/platform_ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,24 @@ import {
} from '../change_detection/scheduling/ng_zone_scheduling';
import {ChangeDetectionScheduler} from '../change_detection/scheduling/zoneless_scheduling';
import {ChangeDetectionSchedulerImpl} from '../change_detection/scheduling/zoneless_scheduling_impl';
import {Injectable, Injector} from '../di';
import {Injectable, Injector, StaticProvider} from '../di';
import {errorHandlerEnvironmentInitializer} from '../error_handler';
import {RuntimeError, RuntimeErrorCode} from '../errors';
import {Type} from '../interface/type';
import {CompilerOptions} from '../linker';
import {getNgZone} from '../zone/ng_zone';
import {NgModuleFactory, NgModuleRef} from '../linker/ng_module_factory';
import {createNgModuleRefWithProviders} from '../render3/ng_module_ref';
import {getNgZone} from '../zone/ng_zone';
import {bootstrap, setModuleBootstrapImpl} from './bootstrap';
import {PLATFORM_DESTROY_LISTENERS} from './platform_destroy_listeners';

// Holds the set of providers to be used for the *next* application to be bootstrapped.
// Used only for providing the zone related providers by default with `downgradeModule`.
let _additionalApplicationProviders: StaticProvider[] | undefined = undefined;
Comment thread
atscott marked this conversation as resolved.
export function setZoneProvidersForNextBootstrap(): void {
_additionalApplicationProviders = internalProvideZoneChangeDetection({});
}

/**
* The Angular platform is the entry point for Angular on a web page.
* Each page has exactly one platform. Services (such as reflection) which are common
Expand All @@ -39,6 +46,7 @@ export class PlatformRef {
private _modules: NgModuleRef<any>[] = [];
private _destroyListeners: Array<() => void> = [];
private _destroyed: boolean = false;
private _additionalApplicationProviders?: StaticProvider[];

/** @internal */
constructor(private _injector: Injector) {}
Expand Down Expand Up @@ -67,8 +75,10 @@ export class PlatformRef {
ngZoneFactory,
}),
{provide: ChangeDetectionScheduler, useExisting: ChangeDetectionSchedulerImpl},
...(_additionalApplicationProviders ?? []),
errorHandlerEnvironmentInitializer,
];
_additionalApplicationProviders = undefined;
const moduleRef = createNgModuleRefWithProviders(
moduleFactory.moduleType,
this.injector,
Expand Down
6 changes: 3 additions & 3 deletions packages/core/test/bundling/defer/bundle.golden_symbols.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
"shimStylesContent"
],
"lazy": [
"DeferComponent",
"_DeferComponent",
"AFTER_RENDER_SEQUENCES_TO_ADD",
"ANIMATIONS",
"APP_BOOTSTRAP_LISTENER",
Expand Down Expand Up @@ -802,9 +804,7 @@
"wasLastNodeCreated",
"writeDirectClass",
"writeDirectStyle",
"writeToDirectiveInput",
"DeferComponent",
"_DeferComponent"
"writeToDirectiveInput"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@
"_a5",
"_a6",
"_a7",
"_additionalApplicationProviders",
"_applyRootElementTransformImpl",
"_arrayIndexOfSorted",
"_bind",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@
"_a5",
"_a6",
"_a7",
"_additionalApplicationProviders",
"_applyRootElementTransformImpl",
"_arrayIndexOfSorted",
"_bind",
Expand Down
8 changes: 7 additions & 1 deletion packages/upgrade/static/src/downgrade_module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
PlatformRef,
StaticProvider,
Type,
ɵsetZoneProvidersForNextBootstrap,
} from '@angular/core';
import {platformBrowser} from '@angular/platform-browser';

Expand Down Expand Up @@ -393,6 +394,11 @@ export function downgradeModule<T>(
bootstrapFn = moduleOrBootstrapFn;
}

const wrappedBootstrapFn = (extraProviders: StaticProvider[]) => {
ɵsetZoneProvidersForNextBootstrap();
return bootstrapFn(extraProviders);
};

let injector: Injector;

// Create an ng1 module to bootstrap.
Expand All @@ -415,7 +421,7 @@ export function downgradeModule<T>(
($injector: ɵangular1.IInjectorService) => {
setTempInjectorRef($injector);
const result: ɵutil.LazyModuleRef = {
promise: bootstrapFn(angular1Providers).then((ref) => {
promise: wrappedBootstrapFn(angular1Providers).then((ref) => {
injector = result.injector = new NgAdapterInjector(ref.injector);
injector.get(ɵconstants.$INJECTOR);

Expand Down
3 changes: 2 additions & 1 deletion packages/upgrade/static/src/upgrade_module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
PlatformRef,
Testability,
ɵNoopNgZone,
ɵinternalProvideZoneChangeDetection,
} from '@angular/core';

import {ɵangular1, ɵconstants, ɵutil} from '../common';
Expand Down Expand Up @@ -145,7 +146,7 @@ import {NgAdapterInjector} from './util';
*
* @publicApi
*/
@NgModule({providers: [angular1Providers]})
@NgModule({providers: [angular1Providers, ɵinternalProvideZoneChangeDetection({})]})
export class UpgradeModule {
/**
* The AngularJS `$injector` for the upgrade application.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
OnChanges,
OnDestroy,
Output,
provideZoneChangeDetection,
SimpleChanges,
} from '@angular/core';
import {fakeAsync, tick, waitForAsync} from '@angular/core/testing';
Expand Down Expand Up @@ -463,7 +462,6 @@ withEachNg1Version(() => {
@NgModule({
imports: [BrowserModule, UpgradeModule],
declarations: [Ng2Component],
providers: [provideZoneChangeDetection()],
})
class Ng2Module {
ngDoBootstrap() {}
Expand Down
16 changes: 0 additions & 16 deletions packages/upgrade/static/test/integration/downgrade_module_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
OnChanges,
OnDestroy,
OnInit,
provideZoneChangeDetection,
StaticProvider,
Type,
ViewRef,
Expand Down Expand Up @@ -488,7 +487,6 @@ withEachNg1Version(() => {
{provide: 'FOO', useValue: 'Mod-foo'},
{provide: 'BAR', useValue: 'Mod-bar'},
{provide: 'BAZ', useValue: 'Mod-baz'},
provideZoneChangeDetection(),
],
})
class Ng2Module {
Expand Down Expand Up @@ -686,7 +684,6 @@ withEachNg1Version(() => {
@NgModule({
declarations: [Ng2AComponent, Ng2BComponent],
imports: [BrowserModule],
providers: [provideZoneChangeDetection()],
})
class Ng2Module {
ngDoBootstrap() {}
Expand Down Expand Up @@ -756,7 +753,6 @@ withEachNg1Version(() => {
useFactory: (i: angular.IInjectorService) => i.get('ng1Value'),
deps: ['$injector'],
},
provideZoneChangeDetection(),
],
})
class Ng2Module {
Expand Down Expand Up @@ -807,7 +803,6 @@ withEachNg1Version(() => {
@NgModule({
declarations: [Ng2Component],
imports: [BrowserModule],
providers: [provideZoneChangeDetection()],
})
class Ng2Module {
ngDoBootstrap() {}
Expand Down Expand Up @@ -847,7 +842,6 @@ withEachNg1Version(() => {
@NgModule({
declarations: [Ng2Component],
imports: [BrowserModule],
providers: [provideZoneChangeDetection()],
})
class Ng2Module {
ngDoBootstrap() {}
Expand Down Expand Up @@ -892,7 +886,6 @@ withEachNg1Version(() => {
@NgModule({
declarations: [Ng2Component],
imports: [BrowserModule],
providers: [provideZoneChangeDetection()],
})
class Ng2Module {
ngDoBootstrap() {}
Expand Down Expand Up @@ -967,7 +960,6 @@ withEachNg1Version(() => {
@NgModule({
declarations: [TestComponent, WrapperComponent],
imports: [BrowserModule],
providers: [provideZoneChangeDetection()],
})
class Ng2Module {
ngDoBootstrap() {}
Expand Down Expand Up @@ -1018,7 +1010,6 @@ withEachNg1Version(() => {
@NgModule({
declarations: [Ng2Component],
imports: [BrowserModule],
providers: [provideZoneChangeDetection()],
})
class Ng2Module {
ngDoBootstrap() {}
Expand Down Expand Up @@ -1073,7 +1064,6 @@ withEachNg1Version(() => {
@NgModule({
declarations: [TestComponent, WrapperComponent],
imports: [BrowserModule],
providers: [provideZoneChangeDetection()],
})
class Ng2Module {
ngDoBootstrap() {}
Expand Down Expand Up @@ -1167,7 +1157,6 @@ withEachNg1Version(() => {
@NgModule({
declarations: [Ng2Component],
imports: [BrowserModule],
providers: [provideZoneChangeDetection()],
})
class Ng2Module {
ngDoBootstrap() {}
Expand Down Expand Up @@ -1310,7 +1299,6 @@ withEachNg1Version(() => {
@NgModule({
declarations: [Ng2Component],
imports: [BrowserModule],
providers: [provideZoneChangeDetection()],
})
class Ng2Module {
ngDoBootstrap() {}
Expand Down Expand Up @@ -1362,7 +1350,6 @@ withEachNg1Version(() => {
@NgModule({
declarations: [Ng2Component],
imports: [BrowserModule],
providers: [provideZoneChangeDetection()],
})
class Ng2Module {
ngDoBootstrap() {}
Expand Down Expand Up @@ -1432,7 +1419,6 @@ withEachNg1Version(() => {

@NgModule({
declarations: [Ng2Component],
providers: [provideZoneChangeDetection()],
imports: [BrowserModule],
})
class Ng2Module {
Expand Down Expand Up @@ -1493,7 +1479,6 @@ withEachNg1Version(() => {
@NgModule({
declarations: [Ng2Component],
imports: [BrowserModule],
providers: [provideZoneChangeDetection()],
})
class Ng2Module {
constructor(injector: Injector) {
Expand Down Expand Up @@ -1528,7 +1513,6 @@ withEachNg1Version(() => {
@NgModule({
declarations: [Ng2Component],
imports: [BrowserModule],
providers: [provideZoneChangeDetection()],
})
class Ng2Module {
ngDoBootstrap() {}
Expand Down