Skip to content

Commit

Permalink
fix(@schematics/angular): remove CommonModule import from standalone …
Browse files Browse the repository at this point in the history
…components

`ng g c` no longer generates a component with the `CommonModule` import.
This import is not useful if developers adopt the control flow syntax in their templates.
Instead, developers are encouraged to import the individual directives/pipes if needed.
  • Loading branch information
cexbrayat committed Nov 22, 2023
1 parent 07834da commit eecdd7d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { <% if(changeDetection !== 'Default') { %>ChangeDetectionStrategy, <% }%>Component<% if(!!viewEncapsulation) { %>, ViewEncapsulation<% }%> } from '@angular/core';<% if(standalone) {%>
import { CommonModule } from '@angular/common';<% } %>
import { <% if(changeDetection !== 'Default') { %>ChangeDetectionStrategy, <% }%>Component<% if(!!viewEncapsulation) { %>, ViewEncapsulation<% }%> } from '@angular/core';

@Component({<% if(!skipSelector) {%>
selector: '<%= selector %>',<%}%><% if(standalone) {%>
standalone: true,
imports: [CommonModule],<%}%><% if(inlineTemplate) { %>
imports: [],<%}%><% if(inlineTemplate) { %>
template: `
<p>
<%= dasherize(name) %> works!
Expand Down
2 changes: 1 addition & 1 deletion packages/schematics/angular/component/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ describe('Component Schematic', () => {
expect(componentContent).toContain('class FooComponent');
expect(moduleContent).not.toContain('FooComponent');
expect(componentContent).toContain('standalone: true');
expect(componentContent).toContain('imports: [CommonModule]');
expect(componentContent).toContain('imports: []');
});

it('should declare standalone components in the `imports` of a test', async () => {
Expand Down

0 comments on commit eecdd7d

Please sign in to comment.