diff --git a/packages/schematics/angular/application/files/module-files/src/app/app__typeSeparator__module.ts.template b/packages/schematics/angular/application/files/module-files/src/app/app__typeSeparator__module.ts.template index 06ba3eb2a079..f7ad6f2cb515 100644 --- a/packages/schematics/angular/application/files/module-files/src/app/app__typeSeparator__module.ts.template +++ b/packages/schematics/angular/application/files/module-files/src/app/app__typeSeparator__module.ts.template @@ -1,4 +1,4 @@ -import { NgModule, provideBrowserGlobalErrorListeners } from '@angular/core'; +import { NgModule, provideBrowserGlobalErrorListeners<% if(!zoneless) { %>, provideZoneChangeDetection<% } %> } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; <% if (routing) { %> import { AppRoutingModule } from './app-routing<%= typeSeparator %>module';<% } %> @@ -13,7 +13,8 @@ import { App } from './app<%= suffix %>'; AppRoutingModule<% } %> ], providers: [ - provideBrowserGlobalErrorListeners() + provideBrowserGlobalErrorListeners(),<% if(!zoneless) { %> + provideZoneChangeDetection({ eventCoalescing: true }),<% } %> ], bootstrap: [App] }) diff --git a/packages/schematics/angular/application/files/module-files/src/main.ts.template b/packages/schematics/angular/application/files/module-files/src/main.ts.template index 629780834c82..f74887b16867 100644 --- a/packages/schematics/angular/application/files/module-files/src/main.ts.template +++ b/packages/schematics/angular/application/files/module-files/src/main.ts.template @@ -3,7 +3,6 @@ import { AppModule } from './app/app<%= typeSeparator %>module'; platformBrowser().bootstrapModule(AppModule, { - <% if(!zoneless) { %>ngZoneEventCoalescing: true,<% } %><% if(!!viewEncapsulation) { %> - defaultEncapsulation: ViewEncapsulation.<%= viewEncapsulation %><% } %> + <% if(!!viewEncapsulation) { %> defaultEncapsulation: ViewEncapsulation.<%= viewEncapsulation %><% } %> }) .catch(err => console.error(err)); diff --git a/packages/schematics/angular/application/index_spec.ts b/packages/schematics/angular/application/index_spec.ts index c2f91d110f27..173a4a0bde56 100644 --- a/packages/schematics/angular/application/index_spec.ts +++ b/packages/schematics/angular/application/index_spec.ts @@ -687,7 +687,7 @@ describe('Application Schematic', () => { }); describe('standalone=false', () => { - it('should add the ngZoneEventCoalescing option by default with zone.js apps', async () => { + it('should add the provideZoneChangeDetection with event coalescing option by default with zone.js apps', async () => { const tree = await schematicRunner.runSchematic( 'application', { @@ -698,8 +698,8 @@ describe('Application Schematic', () => { workspaceTree, ); - const content = tree.readContent('/projects/foo/src/main.ts'); - expect(content).toContain('ngZoneEventCoalescing: true'); + const content = tree.readContent('/projects/foo/src/app/app-module.ts'); + expect(content).toContain('provideZoneChangeDetection({ eventCoalescing: true })'); }); it(`should set 'defaultEncapsulation' in main.ts when 'ViewEncapsulation' is provided`, async () => { @@ -890,6 +890,17 @@ describe('Application Schematic', () => { }); describe('standalone: false', () => { + it('should add the provideZoneChangeDetection with event coalescing option by default with zone.js apps', async () => { + const options = { + ...defaultOptions, + standalone: false, + zoneless: false, + fileNameStyleGuide: '2016' as const, + }; + const tree = await schematicRunner.runSchematic('application', options, workspaceTree); + const content = tree.readContent('/projects/foo/src/app/app.module.ts'); + expect(content).toContain('provideZoneChangeDetection({ eventCoalescing: true })'); + }); it('should create a component with the correct template and style urls', async () => { const options = { ...defaultOptions, diff --git a/packages/schematics/angular/utility/standalone/rules_spec.ts b/packages/schematics/angular/utility/standalone/rules_spec.ts index 3208ed0d6f04..fe67b6adac65 100644 --- a/packages/schematics/angular/utility/standalone/rules_spec.ts +++ b/packages/schematics/angular/utility/standalone/rules_spec.ts @@ -422,7 +422,7 @@ describe('standalone utilities', () => { assertContains(content, `import { SOME_TOKEN } from '@my/module';`); assertContains( content, - `providers: [provideBrowserGlobalErrorListeners(),{ provide: SOME_TOKEN, useValue: 123 }]`, + `providers: [provideBrowserGlobalErrorListeners(),{ provide: SOME_TOKEN, useValue: 123 },]`, ); });