Replies: 63 comments 226 replies
-
Thank you. That is long due. When we created the style guide in 2016, we only had angular.js ideas in mind and an idea of what Angular would be. We were right in certain things, we were wrong in other things. In any case, that was 8 years ago and I think everything changed (for the better) |
Beta Was this translation helpful? Give feedback.
-
Thank you; this is long overdue. The suffix is pointless and actually means that if you want to import it only once and append the component to the class name, the compiler will have to remove the suffix, which isn't ideal. @jelbourn any thoughts on DI, i think with update to guild Angular needs to take a position on using DI or the new inject service locator |
Beta Was this translation helpful? Give feedback.
-
It would be nice to have a place that group all Angular best practices, with anchor, same as the current guide. |
Beta Was this translation helpful? Give feedback.
-
It might be cool to explain what hook you will need depending on what you are trying to do. The thing I see the most are people using The same goes for |
Beta Was this translation helpful? Give feedback.
-
I think it would be helpful to cover following topics:
Not sure it's 100% Angular-related, but I think it would be valuable to have such guidance. |
Beta Was this translation helpful? Give feedback.
-
Regarding suffixes in class names, I understand the rationale for reusable components that are part of a component library such as Angular Material for example: On the other hand, for application components whose main role is to display data, if we follow the advice in the new style guide, we'll end up with components such as I'm afraid that to comply to the style guide, we end up with TypeScript interfaces named as So I'd find it helpful to keep the |
Beta Was this translation helpful? Give feedback.
-
I don't fully understand the recommendation to avoid services, components, directives, etc., folders. In my opinion, these are often quite useful. I feel the guide lacks a more extensive example that demonstrates a complete application structure. One that includes multiple directives, pipes, services, components, etc., because right now, I better understand what to avoid rather than what is recommended when it comes to organizing folders within src. |
Beta Was this translation helpful? Give feedback.
-
I feel that this style guide is now less of a guide and more of a standards. And I could even see a guide that goes on top of this for more recommendations. But if the goal is to match all projects, I think it would be helpful for any style guides for specifics. A style guide for a CRUD application, or one for public websites, one that is an SPA or one that is a major application with many modules and many teams. Because these are different use cases that would seek guidance on how the Angular team recommends they work at. Modules are mostly removed but their separation is still valid. Also, I wouldn't mind a more strict recommended project setup where you go into detail what would be recommended for spacing, what goes on a new line and what doesn't, where you place comma's and stuff like that. We already have various ESLint plugins and even Angular ones that I think are good for people to use, but what would be the recommendation for making code look the same. Because ultimately I think the goal of these style guides is to get code in a similar style so that anybody can work on an Angular project. Which to me is the main reason to use Angular: because its applications all look similar enough. Right now I have a lot of rules and settings to make sure linters automatically format most of the code and recommend certain changes to make code seem similar. Having a style guide from Angular that brings code to a higher level, would seem like a good idea to me. Even though some folks will be annoyed by a few of the recommendations, the thought of a code standard that is preferred by the team, would greatly benefit the ecosystem. Similarly it doesn't say anything about TSConfig (or its setup) or what you should do with the angular.json configuration. And I feel it should also go into more detail on the testing part. Both unit testing and E2E/integration testing. |
Beta Was this translation helpful? Give feedback.
-
While Angular is well-known for being an opinionated framework, I observe a significant lack of documentation regarding best practices. Personally, I follow the Angular team on social media, and while it's clear to some developers that certain practices are preferred, these are not officially documented. For example, in a discussion at work, I had to convince my colleagues that OnPush is always preferable in modern Angular. Some argued that this preference isn't stated anywhere in official documentation and Angular itself does not come with OnPush as the default strategy. Additional examples of areas where official recommendations would be beneficial include:
Providing clear, official guidance on these and similar topics would greatly benefit the community by reducing ambiguity and helping teams adopt best practices more consistently. |
Beta Was this translation helpful? Give feedback.
-
Just a heads-up on this matter. Since Angular templates are no longer "pure HTML" due to the new control-flow syntax, Prettier relies on the
|
Beta Was this translation helpful? Give feedback.
-
Sometimes, a simple expression is not enough. Will there be a recommendation when the logic required is more complex than teh basic expression parser for the Extending from that...any chance we might get a function to create host bindings when they need to be more complex? Just, really really rough, off the top of my head, maybe: @Component({ ... })
export class AdvancedWidget {
#complexBinding1 = hostBinding(value => /* complex logic here? */, 'atter.whatever');
#keydownHandler = hostListener(($event: Event) => /* complex logic here? */, 'keydown');
} This would be in-line with the new functional input/output/signals stuff, and support whatever level of complexity is necessary with full support for TypeScript's featureset? I feel this would be a better approach, than say...expanding the angular parser for the |
Beta Was this translation helpful? Give feedback.
-
This is a lie :) I don't see you recommending the host property anywhere in the linked draft. I'm also missing a paragraph like "Prefer using the host property over creating a single container element". I see this countless times. <cool-component>
<div class="d-flex flex-grow">
...
</div>
</cool-component> when they should've just done @Component({
host: {
'class': 'd-flex flex-grow'
}
}) |
Beta Was this translation helpful? Give feedback.
-
If we lose the suffixes in the file names, all the pretty angular-specific icons in vscode won't show up, right? Can icons pack work for angular-specific icons without file suffixes? |
Beta Was this translation helpful? Give feedback.
-
I really appreciate this being updated! I do have a question about this:
Are we recommending using Personally, I make an effort to avoid 'root' and provide services where they're needed, with the intention that I don't need Angular to carry around things in memory that don't need to be there. |
Beta Was this translation helpful? Give feedback.
-
If template bindings are protected, how can I test these template bindings in Jasmine tests? Does |
Beta Was this translation helpful? Give feedback.
-
A lot of valuable discussions have taken place in various threads. However, based on my experience, I’d like to highlight a few reasons why I support the use of suffixes in file naming. While there is room for improvement in documentation, having a dedicated section for 'Best Practices for Angular' alongside a 'General Best Practices' section in the Style Guide could provide clear, organized guidance. I've noticed that organizations and teams often adopt different best practices, but establishing a standardized approach would greatly benefit both the community and organizations by promoting the most recommended practices across the board. What I see this RFC that Angular Team is taking Inspiration from React and following Naming Convetions as it is followed there
IMO, having I am not sure but I assume VSCode/JetBrains are using suffix to predict angular specific types they might need to update Language services will need updates to recognise files without suffixes or by Folder name or Decorators which might be a problematic
Regex Pattern for Searching
May lead more results and less performant in large codebase and may result more than what you need to search. File Naming + Import Files POV// OLD Style (Better IMO ✅)
// highlight.directive.ts
@Directive({
selector: '[appHighlight]'
})
export class HighlightDirective {}
// NEW Style Suggested
// highlight.ts
@Directive({
selector: '[appHighlight]'
})
export class Highlight {} It was very evident from now we are importing a component by looking
// Old style - Clear distinction
import { UserComponent } from './user.component';
import { UserService } from './user.service';
// New style - Potential naming conflicts
import { User } from './user';
import { UserData } from './user-data'; IMO, differentiation in case we need to differ "Class vs Interface" in different file that might be problematic // After - Potential conflict (Without suffix might cause confusion)
// user.ts
interface User {...}
// user.ts
class User {...} // Same name! Debugging/StackTraces POV
So Keeping suffix will at-least provide consistency overall in application but in order to make sense for file I think it wilk be better to have better class / filenames [Suggestion for "on" prefix for event handlers]
// on<Action><EventHandler>
onHandleClick
onProcessClick
onSubmitClick
OR
// on<EventHandler><Action>
onClickHandle
onClickProcess
onClickSubmit By maintaining clear, descriptive, and consistent naming conventions with suffixes, developers can avoid the pitfalls of ambiguity and streamline their development process IMO. |
Beta Was this translation helpful? Give feedback.
-
I favor all the new advancements in the framework, like signals, SSR, etc., but please keep the essence of Angular—the core foundation. This is why we love Angular and not React. With each new version of the framework, I get the impression that we are moving closer to React. |
Beta Was this translation helpful? Give feedback.
-
here is few things I think are missing
|
Beta Was this translation helpful? Give feedback.
-
I absolutely loathe this proposal. The solution to the inevitable naming conflicts is just "then name it something else"? UserDataClient instead of UserService? And everyone gets to choose their own suffix? This will only cause confusion and make working together on an Angular project more difficult for beginners. Please never let this become official documentation. There is absolutely nothing wrong with User, User(List)Component, UserService etc. Clear and concise. |
Beta Was this translation helpful? Give feedback.
-
I believe adding Component suffix to all Components is less fun but removing it from all Component is not good either.
For service, I don't see the value of changing the naming I don't use directives a lot, no comment for them |
Beta Was this translation helpful? Give feedback.
-
FYI we're all focused on wrapping up v19 at the moment; we'll come back to this RFC a bit after the release. |
Beta Was this translation helpful? Give feedback.
-
As many others have stated, there's absolutely no sense in renaming users.service.ts into a usersDataClient.ts! It's even more verbose so your argument for less verbosity has no ground. And regarding the component suffix, first find a way of NOT breaking 8 years worth of IDE and extension building around .component suffixes, and only then add it to an official style guide...but then you'd also have to include style guides for interfaces, enums and types and other commonly used files within a component, or should we keep the suffixes for them? You have to think much longer and harder for this. Because all we get as of now is an argument of little bit less verbosity, while breaking dozens of well-established extensions such as icons, linters, searching, etc. Surely Angular team is better than that. At least I was convinced of that, up until now. |
Beta Was this translation helpful? Give feedback.
-
Some extra notes on the suffixes and consistency (IMHO implicit everywhere):
To me it's mostly a matter of trust: the ng team has proved many times that they master very well the concept of "changing without breaking". We got new (and really great) things without even minimal problems. Assuming the contrary is a bit odd IMO! ☮️ |
Beta Was this translation helpful? Give feedback.
-
The new guidelines doesn’t make any sense, Angular is a framework not a library and with dumbing down the style guide you are removing the frame and without the frame there going to be chaos. Stop trying to convert Angular to React, the dev world doesn’t need second React. Angular has reputation of a framework as a first choice when comes to building Enterprise solutions because there are rules and clear structure. |
Beta Was this translation helpful? Give feedback.
-
@mauriziocescon I don't know that those frameworks (except React) actually enforce a PascalCase name. I brought it up, because recent demonstrations of new authoring paradigms used PascalCase. The naming changes to be recommended here, seemed to be in line, with a wholesale shift towards a PascalCase naming structure, with a radically different authoring paradigm for "function" components. My experience with svelt and vue, both used lowercase element names. I don't think angular is really "on its own" here...Angular follows web standards. I think that is a good thing! The HTML standard is such that, all elements become lowercase, even if they are a different casing, semantically. The recommendation is to use lowercase element names. Angular has followed the standard here. As it has with shadow dom/encapsulation, styles, etc. I would also offer that naming is not boilerplate. Repetitive heavy code, such as modules, is boilerplate. I still find value in modules in some cases, but I also appreciate the lesser need to rely on them now. They ARE boilerplate. . Naming, however, especially clear and descriptive naming (which tends towards longer rather than shorter names) is a critical aspect of writing quality, MAINTAINABLE software. I think there have been a lot of voices here that are saying the naming changes as thus far recommended would HURT the Angular ecosystem, make projects less maintainable, lead to more naming conflicts, etc. I generally agree. I understand the motivation. In all fairness, I think services is probably the one area where this change could be made, with minimal impact. Components, pipes, directives, etc. on the other hand, I think could suffer dire impacts from ill-thought naming changes. I also don't know that pipes or directives, really have much "boilerplate". They are pretty darn light weight as they are. Switching to some less verbose approach, such as functional, wouldn't really change all that much. Minimally. You would still need config, the domain of directives right now. You would then still have to implement the functionality...which is really where most of the code goes, for pipes and directives (and validators, etc.) I think modules were really one of the largest areas of angular boilerplate, and there has already been great improvement there with the more functional approach and stand-alone components. FWIW,
Imagine if we dropped all the suffixes... O_o More specifically, imagine if we auto-migrated all such code!! That, really, was/is my main concern...auto-migration scripts. Secondary to that, would be the naming changing by default in new projects. As a seasoned angular developer, boy, the frustration I can foresee encountering if all of a sudden, my unique type names vanished... Naming conflicts, and more time spent figuring out unique naming patterns (which are likely to be different from a project to project basis), searching limitations (what if I want to find all components with a specific pattern in their names? With regex? Boy, the Component suffix is HUGELY valuable! Same goes for all the other suffixes. I was just doing this the other day on a new project. I didn't even realize it at first, then this thread came to mind...) The above naming is a very common, simple, strait forward, non-confusing, easily maintainable approach. Its highly patterened, easy to create custom tooling for (I've written custom Nx schemas for projects where common patterns like this where we had lots of sets of code that followed a similar pattern...the "boilerplate" was a custom schema away from being negated...) If someone still wanted more descriptive services without the Service suffix, ok. Maybe OrderData would make sense... OrderDataClient makes more sense. OrderDataService is only a small difference in comparison. An OrderDataService might do a bit more than simply fetch...it might employ a caching service to do a bit of caching as well. OrderDataCachingService? I feel the service moniker is more clear than the client moniker, but it may well just be a matter of preference, familiarity, etc. I don't see naming as being a boilerplate problem....good descriptive naming, is just good practice. Descriptive names, tend to be longer names. I think most people use an IDE of some kind or other these days. I am not sure if "writes in notepad" really describes the majority. IDEs (especially with ai code completion) make VERY short work of detecting the most likely name that the developer needs, and we rarely type the whole thing out. Which I think nullifies the idea that "naming is boilerplate" even more. I'd like to know when I'm, say working with a Component, just by looking at its name. That at a glance distinctive, clear insight is wonderful. If the class (or even in the future function) is just "Orders"....that's not as clear and descriptive. It runs a higher risk of conflicting name wise. I do understand the motivation. Just want to make sure that a decision isn't made purely on motivation, without fully considering the likely consequences. I think it is pretty clear, there are likely a lot of consequences. I also do think that, recently demonstrated changes proposed for angular (and I know they are just ideas, proposals) really looked like something I'd call Reangular, or Angulact, which I think would be a detrimental turn for angular, if it happened. 🪙 🪙 |
Beta Was this translation helpful? Give feedback.
-
I would like to see an example project in this case, just to see what this would actually look like in say a medium size project. Also I think it would be helpul to provide a comprehensive examples of possible names, not absolutely everything, but because of the current way that we're doing things in Angular it's not just a matter of dropping the names but a mental shift as well and I think that might be harder to overcome. So for me plenty of examples and naming suggestions might make it easier to accept. Right now it's just a concept, I need to see it in action to decide if I really like Angular without suffixes. |
Beta Was this translation helpful? Give feedback.
-
These all look good to me, I have read most feedback from other replies and I honestly think most of them are too subjective, very few make good objective points, but overall I don't think any of the recommended changes is a deal breaker. Angular is moving in the right direction, and if there something people are good at, is adapting, regardless if some of the replies may suggest the opposite. Keep up the good work. |
Beta Was this translation helpful? Give feedback.
-
Getting rid of suffixes might push developers toward creating type-based subfolders for services, components, interfaces, directives, etc. Instead of sticking to a clean flat structure, we’d end up with a multi-level maze of files and folders. Sure, that’s one way to do it, but it might clash with some core best practices. I understand that’s not the intention, and that everything can be named properly. However, we need to remember that not everyone is skilled at doing so. In my experience, only a handful of developers are truly good at coming up with meaningful names. Suffixes provided a sort of standardization for naming conventions - helping both experienced and less experienced developers work together more effectively. They allowed teams of juniors, mids, and seniors to align on naming practices without much friction. It’s similar to using a state management library like NgRx. Sure, you can manage state in different ways, inclusing your own custom solution, but developers often prefer standardized tools / frameworks, because they create predictable, consistent patterns, making it easier for new team members to jump into a new project and get started quickly. Leaving every decision about fodler structure or naming conventions entirely up to the team or a lead architect can create more variability or just add unnecessary complexity. |
Beta Was this translation helpful? Give feedback.
-
Freshly back from a long vacation, I think now's a good time to officially wrap up this RFC! We're going to make some adjustments to the proposed style guide based on feedback here. The summary is here: #59522 |
Beta Was this translation helpful? Give feedback.
-
Hey all- we've posted another update to #59522 |
Beta Was this translation helpful? Give feedback.
-
Introduction
Angular's current style guide was originally written in 2016, just as v2.0.0 released. A lot has
changed in the intervening eight years.
This RFC proposes a significant overhaul of Angular's style guide
with a handful of primary goals:
help ourselves)
As always, keep our code of conduct in mind. We know that a proposal of this scope affects the way the community writes Angular code, and that people have invested their time and energy learning these practices in the past. We appreciate your commitment and investment in this project and ask to keep comments respectful. Remember, we are all just folks doing our best with limited resources.
📜 Full draft of the revised style guide
What kind of feedback are we looking for?
We're happy to take any and all feedback on this update. However, we're primarily interested in
the following:
these changes?
Notable changes
Remove general code health guidance that's not meaningfully related to Angular
The current style guide includes a significant amount of advice relating to general coding best
practices. Examples include:
While these are reasonable best practices, they're not really specific to Angular. There's a massive
corpus of books, articles, and videos dedicated to general coding best practices; we believe that
the Angular style guide will be more useful focused on framework-specific practices without trying
to curate a subset of these more general practices.
The revised guide still includes some general advice, mostly where such advice brushes close to a
particular aspect of writing Angular code.
Move Angular best practices to appropriate documentation instead of the style guide
We want the style guide to focus on coding style. Much of the content in the existing style
guide instead relates to Angular best practices. For the most part, this best practice advice has
moved (or will move) to the appropriate documentation page.
For example, guidance on choosing component selectors has moved to
the documentation page for component selector.
Stop recommending suffixing most file names and class names with the type of construct
The current style guide recommends suffixing file names and class names with the type of Angular
construct. For example:
user-profile.component.ts
andUserProfileComponent
campaign-data.service.ts
andCampaignDataService
Over time, we've observed that this naming convention can make the framework feel cumbersome and
boilerplate-y, especially for new developers unaccustomed to this practice.
For class naming, we believe it's better for a class name to reflect the class's behavior and
responsibilities, not how it's used. The term "service", in particular, does not add any
meaningful information to explain what a class does. Thus, this naming convention can sometimes lead
to less helpful names for classes. For example, a name like
UserDataClient
tells you much moreabout what a class does than
UserService
. As a result of our observations, we're reversingthis guidance.
There are two exceptions to this change: Pipes and NgModules.
sense to keep class names like "DatePipe". As with
NgModule
, the file name wouldbecome
date-pipe.ts
.Remove (almost) all guidance related to
NgModule
A large portion of the current style guide pertains to
NgModule
— when to use them, how to organizethem, etc. The Angular team now recommends using standalone components and
providedIn: 'root'
over
NgModule
, so this guidance can be removed from future versions of the style guide. All of thehistoric
NgModule
guidance will remain accessible on the archived versionsof angular.dev.
Remove suggestion to put templates in a separate file
The current style guide recommends extracting component templates to a template file if they exceed
three lines. Since this was written, the popularity of both JSX-based template styles and
single-file component formats has exploded. Because of this change in the broader ecosystem, we no
longer see it as necessary to strictly recommend moving templates to a separate file.
This change does not mean that inline templates will be recommended- the change is that separate
files and inline templates are both acceptable. You can still have an opinion for your projects, but
the Angular team no longer takes a stance here.
Stop recommending
@HostBinding
and@HostListener
The current style guide recommends
@HostBinding
and@HostListener
over thehost
property inthe
@Component
and@Directive
decorator. The updated style guide reverses this advice.Astute readers may have already noticed this updated guidance in the rewritten Components guide
on angular.dev and discussion on this topic in the signal-based components RFC.
There are a number of reasons for this change:
decorators, making
@HostBinding
and@HostListener
somewhat misaligned with this more modernAPI style.
host
object matches the syntax used in the template, leading to a more consistentexperience.
host
property is easier to quickly scan. CSS classes alone aremuch easier to reason about when they're all defined in one place, and seeing ARIA attributes
all together helps sanity check that the right attributes are applied.
HostListener
doesn't support expressions, which encourages developers to create unnecessaryone-line methods.
HostBinding
doesn't allow for static values (e.g.role
andtabindex
), leading to unnecessarydynamic bindings.
One downside to the
host
object is that Angular does not yet do any type-checking on expressionsin
host
bindings. The team is acutely aware of this gap and plans to add type checking forhost
in the not-too-distant future.
Stop recommending the "on" prefix for event handlers
The current style guide recommends prefixing event handler names with "on", such as
onClick
or
onKeydown
. The updated advice is to name methods for what they do rather than when they'recalled.
Frequently asked questions
Why change the style guide at all?
**Angular has evolved a lot! ** Since the style guide was written, we've moved from
NgModule
tostandalone components, introduced signals, new control flow syntax, and so much more.
**We've seen eight years worth of Angular codebases! ** The current style guide was written when
Angular was still quite new. As we've seen so much Angular code written over the years, we've had
time to rethink some of the practices recommended in the guide.
The web ecosystem has changed a lot! Developers had certain notions and preferences around web
development in 2016 that have shifted over time. For example, the popularity of the single file
component authoring style in frameworks like Vue and Svelte have demonstrated that opinions have
shifted about separating code and templates into separate files.
But I like the old way!
That's okay! Ultimately the style guide is just a set of recommendations- the framework will still
work fine if you decide to stick with the original conventions. Historic versions of the style guide
will remain available in the archived versions of angular.dev. But we think
the updates proposed here constitute a better set of recommendations for new code going forward.
Will community tools (like angular-eslint) support the new recommendations?
We plan to coordinate with community supported tool owners so that they can be updated alongside
the revised style guide becoming official.
Will this new style guide land in version 19?
No— these changes aren't ready for v19, so they'll land in a later version.
Why doesn't the guide recommend signals?
While signals are maturing rapidly, some APIs remain in developer preview and some parts of the
ecosystem (forms, router) have yet to receive a signals makeover. We'll do continue to update the
guide as signals continue to mature.
Will you update the code generated by
ng new
?Yes- we consider updating the code generated by
ng new
to be a requirement for publishing updatesto the style guide.
Will you provide schematics to refactor code to follow the new guidance?
We plan to offer optional refactoring schematics to update code to the new guidelines where it's
feasible. These schematics would be opt-in and not automatically run as part of
ng update
.Beta Was this translation helpful? Give feedback.
All reactions