You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add Default Prettier Configuration for Angular Templates #30548
Which @angular/* package(s) are relevant/related to the feature request?
No response
Description
Hello Angular Team,
Since Angular v20, component files no longer use the .component suffix by default. As a result, associated template files (e.g., my-feature.html) are no longer automatically recognized by Prettier as Angular templates. This leads Prettier to fall back to its default HTML parser, which doesn't handle Angular-specific syntax correctly.
Proposed solution
To improve the developer experience and avoid formatting issues, it would be helpful for new Angular projects to include a default Prettier configuration specifying the Angular parser for .html files.
This configuration ensures consistent and correct formatting of Angular templates out of the box, without requiring manual setup from the developer. It aligns with Angular’s philosophy of providing strong defaults for common tooling.
Thanks for considering this improvement!
Alternatives considered
Instead of package.json, we could consider having a .prettierrc file to set prettier configuration.
Reacted by Bartosz Zygmunt, Nicolas Balao, Vojtech Mašek, Jan Olaf Martin and Matthieu Riegler
Another simple and effective solution would be to set the ngHtml option to true by default for the @schematics/angular:component schematic in angular.json, like so:
This change would suffix all component template files with .ng.html, enabling Prettier to automatically apply its Angular parser.
The main challenge is that Prettier currently cannot distinguish Angular templates from regular HTML files unless they follow a specific naming convention like .ng.html.
This change would suffix all component template files with .ng.html, enabling Prettier to automatically apply its Angular parser.
I only skimmed the prettier code and didn't try anything out but from what I've seen .ng.html has no special handling in prettier today. Or is that setup somewhere else?
We're adding the prettier section to new package.json files starting with the next release of v20. Thanks for bringing this up! This is definitely a sharp edge with the new filenames that we'll take another look at.
Activity
vmasek commentedon Jun 23, 2025
Example of the same control flow formatted by prettier (3.6.0)
with
.componentsuffix:and without the suffix:
Mikastark commentedon Jun 24, 2025
Another simple and effective solution would be to set the ngHtml option to true by default for the @schematics/angular:component schematic in angular.json, like so:
This change would suffix all component template files with .ng.html, enabling Prettier to automatically apply its Angular parser.
The main challenge is that Prettier currently cannot distinguish Angular templates from regular HTML files unless they follow a specific naming convention like .ng.html.
hybrist commentedon Jun 24, 2025
I only skimmed the prettier code and didn't try anything out but from what I've seen
.ng.htmlhas no special handling in prettier today. Or is that setup somewhere else?fix(@schematics/angular): add missing prettier config
fix(@schematics/angular): add missing prettier config
fix(@schematics/angular): add missing prettier config
hybrist commentedon Jun 24, 2025
We're adding the
prettiersection to newpackage.jsonfiles starting with the next release of v20. Thanks for bringing this up! This is definitely a sharp edge with the new filenames that we'll take another look at.robertIsaac commentedon Jun 25, 2025
hi @jkrems
why it was decided to go with prettier in the package.json instead of prettierrc file?
angular-automatic-lock-bot commentedon Jul 26, 2025
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.