Skip to content

Commit c2f7081

Browse files
dgp1130alan-agius4
authored andcommitted
refactor(@schematics/angular): update component schematic to use single style or styleUrl property
An array is no longer required in v17 and we always generate a single style or style URL anyways, so we may as well drop the array. (cherry picked from commit 7b1fd9c)
1 parent 8899fb9 commit c2f7081

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@ import { CommonModule } from '@angular/common';<% } %>
1111
</p>
1212
`<% } else { %>
1313
templateUrl: './<%= dasherize(name) %><%= type ? '.' + dasherize(type): '' %>.html'<% } if(inlineStyle) { %>,
14-
styles: [<% if(displayBlock){ %>
15-
`
16-
:host {
17-
display: block;
18-
}
19-
`<% } %>
20-
]<% } else if (style !== 'none') { %>,
21-
styleUrls: ['./<%= dasherize(name) %><%= type ? '.' + dasherize(type): '' %>.<%= style %>']<% } %><% if(!!viewEncapsulation) { %>,
14+
styles: `<% if(displayBlock){ %>
15+
:host {
16+
display: block;
17+
}
18+
<% } %>`<% } else if (style !== 'none') { %>,
19+
styleUrl: './<%= dasherize(name) %><%= type ? '.' + dasherize(type): '' %>.<%= style %>'<% } %><% if(!!viewEncapsulation) { %>,
2220
encapsulation: ViewEncapsulation.<%= viewEncapsulation %><% } if (changeDetection !== 'Default') { %>,
2321
changeDetection: ChangeDetectionStrategy.<%= changeDetection %><% } %>
2422
})

packages/schematics/angular/component/index_spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ describe('Component Schematic', () => {
210210
const options = { ...defaultOptions, inlineStyle: true };
211211
const tree = await schematicRunner.runSchematic('component', options, appTree);
212212
const content = tree.readContent('/projects/bar/src/app/foo/foo.component.ts');
213-
expect(content).toMatch(/styles: \[/);
214-
expect(content).not.toMatch(/styleUrls: /);
213+
expect(content).toMatch(/styles: `/);
214+
expect(content).not.toMatch(/styleUrl: /);
215215
expect(tree.files).not.toContain('/projects/bar/src/app/foo/foo.component.css');
216216
});
217217

@@ -247,7 +247,7 @@ describe('Component Schematic', () => {
247247
const options = { ...defaultOptions, style: Style.Sass };
248248
const tree = await schematicRunner.runSchematic('component', options, appTree);
249249
const content = tree.readContent('/projects/bar/src/app/foo/foo.component.ts');
250-
expect(content).toMatch(/styleUrls: \['.\/foo.component.sass/);
250+
expect(content).toMatch(/styleUrl: '.\/foo.component.sass/);
251251
expect(tree.files).toContain('/projects/bar/src/app/foo/foo.component.sass');
252252
expect(tree.files).not.toContain('/projects/bar/src/app/foo/foo.component.css');
253253
});

0 commit comments

Comments
 (0)