Key takeaway
- Angular coding style guide for teams: naming, feature folders, inject(), computed signals and handler names from the official angular.dev guide.
What is the Angular coding style guide?
The Angular coding style guide is the set of naming, structure and component conventions published by the Angular team on angular.dev. The current Angular style guide is part of the v22 documentation and covers Angular application code only; for general TypeScript it defers to Google's TypeScript style guide.
Its status matters to a technical leader. According to angular.dev, the recommendations are not required for Angular to work. They exist to make code consistent across projects and teams, which lowers review cost and onboarding time. This page turns the guide into rules a team can adopt, and links to reusable Angular components for the design side.
What does the Angular style guide say about naming and file structure?
The guide keeps naming simple: one convention for every file, and names that tell a reader what the file holds. Structure follows the same idea. Group a component's files, keep tests next to the code they test, and organise by feature.
| Area | Rule in the guide | Why it helps |
|---|---|---|
| File names | Separate words with hyphens, for example user-profile.ts | One predictable pattern across the repository |
| Tests | Use the .spec.ts suffix on the same base name as the source file | Tests are found next to the code they cover |
| Main identifier | Name the file after its primary class; avoid helpers.ts, utils.ts, common.ts | A file name says what the file is |
| Component files | Share one base name across .ts, .html and style files | Related files sort together |
| Folders | Organise by feature, not by type (components, directives, services) | A feature can be owned, moved or removed as a unit |
| Size | Usually one component, directive or service per file; when unsure, choose smaller files | Smaller review surface |
| Entry point | Bootstrap in src/main.ts; UI code under src | Non-UI scripts stay outside the application source |
Source: Angular style guide, read 13 Nov 2026.
How should components and directives be written?
The component rules aim at one thing: keep the component about presentation. Logic that does not depend on the view, such as validation or data transformation, belongs in separate files that can be tested without rendering anything.
Group Angular members first and limit visibility
Place injected dependencies, inputs, outputs and queries before methods. Mark members used only by the template as protected, and mark Angular-initialised properties (input, model, output and queries) as readonly. With decorators, the guide applies readonly to outputs and queries but not inputs.
import { Component, computed, inject, input, output } from '@angular/core';
import { OrderService } from './order.service';
@Component({
selector: 'app-order-summary',
templateUrl: './order-summary.html',
styleUrl: './order-summary.css',
})
export class OrderSummary {
private readonly orders = inject(OrderService);
readonly orderId = input.required<string>();
readonly approved = output<string>();
protected readonly label = computed(() => `Order ${this.orderId()}`);
protected approveOrder(): void {
this.orders.approve(this.orderId());
this.approved.emit(this.orderId());
}
}
This is an illustration written for this article, not a copy from the guide. It shows inject() for dependencies, a computed signal for template text and a handler named for its action. Confirm the signal-based input and output APIs for your Angular version on the official page.
Name handlers by action and keep lifecycle hooks thin
The guide asks for handlers named for what they do, for example saveUserData(), and not for the event that triggers them. It also asks you to keep lifecycle hooks such as ngOnInit simple by moving logic into well-named methods the hook calls, and to implement the lifecycle interfaces (OnInit and similar) so the compiler checks the method names.
Prefer class and style bindings, and prefix directives
The guide prefers class and style bindings over NgClass and NgStyle for simpler syntax and better performance. Directive selectors should use the application prefix, with camelCase for attribute selectors, for example [mrTooltip].
Where should logic live: component, service or template?
Keep the template free of complicated expressions, keep the component focused on presentation, and put data access and business rules in injectable services reached through inject(). The guide states the first two rules directly. The service rule is the long-standing Angular pattern: see Angular dependency injection for how providers and injection work.
| Concern | Put it in | Rule source |
|---|---|---|
| Complicated expression | A computed signal in the component class | angular.dev style guide |
| Validation or data transformation | A separate file or function the component calls | angular.dev style guide |
| Server calls and shared state | An injectable service, obtained with inject() | Angular dependency injection pattern; confirm on the official page |
| Event reaction | A handler named for its action, kept short | angular.dev style guide |
| Startup work | A well-named method called from the lifecycle hook | angular.dev style guide |
What has changed since older Angular style guides?
Many articles still teach advice from earlier eras of Angular. The current guide differs in several places, and teams that copy old rules into their own standard end up fighting the framework.
| Topic | Older advice you may meet | Current guide |
|---|---|---|
| Dependency injection | Constructor parameters only | Prefer inject() over constructor parameters |
| Conditional classes | NgClass and NgStyle | Prefer class and style bindings |
| Template logic | Expressions in the template | Move complicated logic into TypeScript, typically computed signals |
| Folders | Folders by type | Folders by feature |
| Event handlers | Named after the event, such as onClick | Named after the action, such as saveUserData() |
| File size | A fixed line limit for functions | The guide gives no line limit; it says one concept per file and smaller files when unsure |
Supported Angular versions change often. According to angular.dev's version page, read 13 Nov 2026, actively supported versions were 20.x, 21.x and 22.x. Confirm the current table on the official page before you set a baseline.
How do you adopt an Angular style guide in a team?
- Adopt the official guide as the baseline. Write down only the places where your team deliberately differs.
- Follow the consistency rule. The guide says that when a file's existing style conflicts with it, keep the file consistent with itself. Fix style in files you are already changing, not in one large rewrite.
- Automate what can be automated. Use your linter and formatter for naming and ordering rules, so review time goes to design.
- Migrate dependency injection gradually. The guide mentions an automated migration to inject(); confirm the command on the official page and run it per feature folder.
- Review at the boundary. New components get the full rule set; legacy components are touched only when changed.
If AI coding assistants write part of your Angular code, a style guide becomes a control as well as a convention. ElixirData Context OS keeps governed context, versioned policy and decision traces in one decision layer above AI agents, which is where rules such as your coding standard can be held for agents to follow. For checking generated work, AgentQA provides automated quality assurance for AI.
When should you not follow the guide strictly?
Do not rewrite a working codebase only to match the guide; the guide itself favours consistency within a file. Do not force small, closely related classes into separate files where the guide allows them to share one. Treat each rule as a default, record the exceptions, and revisit them when you upgrade Angular.
To map one engineering standard your AI agents should follow, and the context and policy it depends on, book a Context Workshop. See what happens in the workshop.
Angular coding style FAQs
Is the Angular style guide mandatory?
No. According to angular.dev, the recommendations are not required for Angular to work. They exist to promote consistency across projects, and where an existing file conflicts with the guide, the guide says to keep that file consistent with itself.
How should I name files in an Angular project?
Hyphenate file names (for example user-profile.ts), use .spec.ts for tests, name each file after its main identifier, and share one base name across a component's .ts, .html and style files. Avoid generic names such as helpers.ts, utils.ts or common.ts.
Should I use constructor injection or inject()?
The current guide prefers the inject() function over constructor parameters, citing readability, comments, type inference and cleaner field initialisation. An automated migration is available; confirm the command on the official page.
Should I organise Angular code by type or by feature?
By feature. The guide recommends feature-based folders over type-based folders such as components, directives or services, and suggests splitting crowded directories into subdirectories.
What should an Angular component contain?
Presentation logic. The guide says to move decoupled logic such as validation or data transformation into separate files, and to move complicated template expressions into TypeScript, typically as computed signals.
Related reading
- Reusable Angular components
- Angular dependency injection
- Angular performance optimisation
- Angular learning path for React developers
- Unit testing techniques
Sources: angular.dev/style-guide and angular.dev/reference/versions, both read 13 Nov 2026.
Ready to put AI agents to work? See an ElixirClaw demo: the agentic OS to build, orchestrate and govern AI agents across your enterprise systems.
Explore the XenonStack platform family: ElixirData · ElixirClaw · ElixirHub · NexaStack · MetaSecure · Neural AI · AgentGRC · AgentSRE · AgentAnalyst · AgentInstruct · AgentRAI · AgentScrum · AgentSearch · AgentForce · AI Aviator · SAIF Aviator · CohortIQ · XenonStack AI · XenonStack UAE