Skip to content

Commit c526501

Browse files
committed
fix(@schematics/angular): do not add changeDetection in default template
As the new default is `Eager`, the CLI was adding `changeDetection: ChangeDetectionStrategy.Eager` in every component
1 parent 174c786 commit c526501

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

packages/schematics/angular/component/files/__name@dasherize@if-flat__/__name@dasherize__.__type@dasherize__.ts.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { <% if(changeDetection !== 'Default') { %>ChangeDetectionStrategy, <% }%>Component<% if(!!viewEncapsulation) { %>, ViewEncapsulation<% }%> } from '@angular/core';
1+
import { <% if(changeDetection !== 'Eager') { %>ChangeDetectionStrategy, <% }%>Component<% if(!!viewEncapsulation) { %>, ViewEncapsulation<% }%> } from '@angular/core';
22

33
@Component({<% if(!skipSelector) {%>
44
selector: '<%= selector %>',<%}%><% if(standalone) {%>
@@ -16,7 +16,7 @@ import { <% if(changeDetection !== 'Default') { %>ChangeDetectionStrategy, <% }%
1616
}
1717
<% } %>`,<% } else if (style !== 'none') { %>
1818
styleUrl: './<%= dasherize(name) %><%= type ? '.' + dasherize(type): '' %>.<%= style %>',<% } %><% if(!!viewEncapsulation) { %>
19-
encapsulation: ViewEncapsulation.<%= viewEncapsulation %>,<% } if (changeDetection !== 'Default') { %>
19+
encapsulation: ViewEncapsulation.<%= viewEncapsulation %>,<% } if (changeDetection !== 'Eager') { %>
2020
changeDetection: ChangeDetectionStrategy.<%= changeDetection %>,<% } %>
2121
})
2222
export <% if(exportDefault) {%>default <%}%>class <%= classifiedName %> {

packages/schematics/angular/component/index_spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ describe('Component Schematic', () => {
7272
expect(tsContent).toMatch(/changeDetection: ChangeDetectionStrategy.OnPush/);
7373
});
7474

75+
it('should not set changeDetection by default', async () => {
76+
const options = { ...defaultOptions };
77+
78+
const tree = await schematicRunner.runSchematic('component', options, appTree);
79+
const tsContent = tree.readContent('/projects/bar/src/app/foo/foo.component.ts');
80+
expect(tsContent).not.toMatch(/changeDetection:/);
81+
expect(tsContent).not.toMatch(/ChangeDetectionStrategy/);
82+
});
83+
7584
it('should not set view encapsulation', async () => {
7685
const options = { ...defaultOptions };
7786

0 commit comments

Comments
 (0)