Skip to content

Commit 00d941c

Browse files
committed
fix(@schematics/angular): correct style guide paths for standalone components
This commit addresses an issue where the standalone application schematic did not correctly handle the `fileNameStyleGuide: '2016'` option. The `templateUrl` and `styleUrl` properties in the generated `app.component.ts` did not include the `.component` suffix, leading to broken links. The key changes are: - Updates the standalone component template to use the `suffix` variable for `templateUrl` and `styleUrl`, ensuring the correct file paths are generated. - Adds a new test case to verify that the generated component has the correct paths when `fileNameStyleGuide: '2016'` is used. (cherry picked from commit 49f12fd)
1 parent c967a44 commit 00d941c

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

packages/schematics/angular/application/files/standalone-files/src/app/app__suffix__.ts.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import { RouterOutlet } from '@angular/router';<% } %>
1111
%><router-outlet /><%
1212
} %>
1313
`,<% } else { %>
14-
templateUrl: './app.html',<% } if(inlineStyle) { %>
14+
templateUrl: './app<%= suffix %>.html',<% } if(inlineStyle) { %>
1515
styles: [],<% } else { %>
16-
styleUrl: './app.<%= style %>'<% } %>
16+
styleUrl: './app<%= suffix %>.<%= style %>'<% } %>
1717
})
1818
export class App {
1919
protected readonly title = signal('<%= name %>');

packages/schematics/angular/application/index_spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,4 +869,14 @@ describe('Application Schematic', () => {
869869
const stylesContent = tree.readContent('/projects/foo/src/styles.css');
870870
expect(stylesContent).toContain('@import "tailwindcss";');
871871
});
872+
873+
describe(`fileNameStyleGuide: '2016'`, () => {
874+
it('should create a component with the correct template and style urls', async () => {
875+
const options = { ...defaultOptions, fileNameStyleGuide: '2016' as const };
876+
const tree = await schematicRunner.runSchematic('application', options, workspaceTree);
877+
const component = tree.readContent('/projects/foo/src/app/app.component.ts');
878+
expect(component).toContain(`templateUrl: './app.component.html'`);
879+
expect(component).toContain(`styleUrl: './app.component.css'`);
880+
});
881+
});
872882
});

0 commit comments

Comments
 (0)