diff --git a/packages/schematics/angular/component/files/__name@dasherize@if-flat__/__name@dasherize__.__type@dasherize__.ts.template b/packages/schematics/angular/component/files/__name@dasherize@if-flat__/__name@dasherize__.__type@dasherize__.ts.template index dcea9394edb8..3ae129c8f1ae 100644 --- a/packages/schematics/angular/component/files/__name@dasherize@if-flat__/__name@dasherize__.__type@dasherize__.ts.template +++ b/packages/schematics/angular/component/files/__name@dasherize@if-flat__/__name@dasherize__.__type@dasherize__.ts.template @@ -1,4 +1,4 @@ -import { <% if(changeDetection !== 'Default') { %>ChangeDetectionStrategy, <% }%>Component<% if(!!viewEncapsulation) { %>, ViewEncapsulation<% }%> } from '@angular/core'; +import { <% if(changeDetection !== 'Eager') { %>ChangeDetectionStrategy, <% }%>Component<% if(!!viewEncapsulation) { %>, ViewEncapsulation<% }%> } from '@angular/core'; @Component({<% if(!skipSelector) {%> selector: '<%= selector %>',<%}%><% if(standalone) {%> @@ -16,7 +16,7 @@ import { <% if(changeDetection !== 'Default') { %>ChangeDetectionStrategy, <% }% } <% } %>`,<% } else if (style !== 'none') { %> styleUrl: './<%= dasherize(name) %><%= type ? '.' + dasherize(type): '' %>.<%= style %>',<% } %><% if(!!viewEncapsulation) { %> - encapsulation: ViewEncapsulation.<%= viewEncapsulation %>,<% } if (changeDetection !== 'Default') { %> + encapsulation: ViewEncapsulation.<%= viewEncapsulation %>,<% } if (changeDetection !== 'Eager') { %> changeDetection: ChangeDetectionStrategy.<%= changeDetection %>,<% } %> }) export <% if(exportDefault) {%>default <%}%>class <%= classifiedName %> { diff --git a/packages/schematics/angular/component/index_spec.ts b/packages/schematics/angular/component/index_spec.ts index 5bff59152715..2a81d9b4acd0 100644 --- a/packages/schematics/angular/component/index_spec.ts +++ b/packages/schematics/angular/component/index_spec.ts @@ -72,6 +72,15 @@ describe('Component Schematic', () => { expect(tsContent).toMatch(/changeDetection: ChangeDetectionStrategy.OnPush/); }); + it('should not set changeDetection by default', async () => { + const options = { ...defaultOptions }; + + const tree = await schematicRunner.runSchematic('component', options, appTree); + const tsContent = tree.readContent('/projects/bar/src/app/foo/foo.component.ts'); + expect(tsContent).not.toMatch(/changeDetection:/); + expect(tsContent).not.toMatch(/ChangeDetectionStrategy/); + }); + it('should not set view encapsulation', async () => { const options = { ...defaultOptions };