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 21c884bd80e8..449172a75604 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 @@ -19,6 +19,6 @@ import { <% if(changeDetection !== 'Default') { %>ChangeDetectionStrategy, <% }% encapsulation: ViewEncapsulation.<%= viewEncapsulation %><% } if (changeDetection !== 'Default') { %>, changeDetection: ChangeDetectionStrategy.<%= changeDetection %><% } %> }) -export class <%= classify(name) %><%= classify(type) %> { +export <% if(exportDefault) {%>default <% } %>class <%= classify(name) %><%= classify(type) %> { } diff --git a/packages/schematics/angular/component/index_spec.ts b/packages/schematics/angular/component/index_spec.ts index ee1d51c3c1a0..510cb14ded1b 100644 --- a/packages/schematics/angular/component/index_spec.ts +++ b/packages/schematics/angular/component/index_spec.ts @@ -496,4 +496,20 @@ describe('Component Schematic', () => { await expectAsync(schematicRunner.runSchematic('component', options, appTree)).toBeRejected(); }); }); + + it('should use export default', async () => { + const options = { ...defaultOptions, exportDefault: true }; + + const tree = await schematicRunner.runSchematic('component', options, appTree); + const tsContent = tree.readContent('/projects/bar/src/app/foo/foo.component.ts'); + expect(tsContent).toMatch('export default class'); + }); + + it('should use named export', async () => { + const options = { ...defaultOptions, exportDefault: false }; + + const tree = await schematicRunner.runSchematic('component', options, appTree); + const tsContent = tree.readContent('/projects/bar/src/app/foo/foo.component.ts'); + expect(tsContent).toMatch('export class'); + }); }); diff --git a/packages/schematics/angular/component/schema.json b/packages/schematics/angular/component/schema.json index e2e3914b41b9..4cdc4f10762b 100644 --- a/packages/schematics/angular/component/schema.json +++ b/packages/schematics/angular/component/schema.json @@ -130,6 +130,11 @@ "type": "boolean", "default": false, "description": "The declaring NgModule exports this component." + }, + "exportDefault": { + "type": "boolean", + "default": false, + "description": "Create a component with default export." } }, "required": ["name", "project"]