XenonStack

Service Design

XenonStack Insights Angular Coding Style Guide: Official Rules Explained

and | Published | Updated

Angular Coding Style Guide: a four-layer stack from the official angular.dev guide up to consistent, reviewable code

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.

Two-column diagram mapping older Angular habits (constructor injection, folders by type, template logic, event-named handlers) to current guide rules (inject(), feature folders, computed signals, action-named handlers)
AreaRule in the guideWhy it helps
File namesSeparate words with hyphens, for example user-profile.tsOne predictable pattern across the repository
TestsUse the .spec.ts suffix on the same base name as the source fileTests are found next to the code they cover
Main identifierName the file after its primary class; avoid helpers.ts, utils.ts, common.tsA file name says what the file is
Component filesShare one base name across .ts, .html and style filesRelated files sort together
FoldersOrganise by feature, not by type (components, directives, services)A feature can be owned, moved or removed as a unit
SizeUsually one component, directive or service per file; when unsure, choose smaller filesSmaller review surface
Entry pointBootstrap in src/main.ts; UI code under srcNon-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.

ConcernPut it inRule source
Complicated expressionA computed signal in the component classangular.dev style guide
Validation or data transformationA separate file or function the component callsangular.dev style guide
Server calls and shared stateAn injectable service, obtained with inject()Angular dependency injection pattern; confirm on the official page
Event reactionA handler named for its action, kept shortangular.dev style guide
Startup workA well-named method called from the lifecycle hookangular.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.

TopicOlder advice you may meetCurrent guide
Dependency injectionConstructor parameters onlyPrefer inject() over constructor parameters
Conditional classesNgClass and NgStylePrefer class and style bindings
Template logicExpressions in the templateMove complicated logic into TypeScript, typically computed signals
FoldersFolders by typeFolders by feature
Event handlersNamed after the event, such as onClickNamed after the action, such as saveUserData()
File sizeA fixed line limit for functionsThe 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?

  1. Adopt the official guide as the baseline. Write down only the places where your team deliberately differs.
  2. 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.
  3. Automate what can be automated. Use your linter and formatter for naming and ordering rules, so review time goes to design.
  4. 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.
  5. 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

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.

Table of Contents

navdeep-singh-gill

Navdeep Singh Gill

Global CEO and Founder of XenonStack

LinkedIn profile

Navdeep Singh Gill is serving as Chief Executive Officer and Product Architect at XenonStack. He holds expertise in building SaaS Platform for Decentralised Big Data management and Governance, AI Marketplace for Operationalising and Scaling. His incredible experience in AI Technologies and Big Data Engineering thrills him to write about different use cases and its approach to solutions.

Get the latest articles in your inbox

Subscribe Now

Interested in Solving your Challenges with XenonStack Team
Get Started

Get Started with your requirements and primary focus, that will help us to make your solution

Please Select your Industry
Banking
Fintech
Payment Providers
Wealth Management
Discrete Manufacturing
Semiconductor
Machinery Manufacturing / Automation
Appliances / Electrical / Electronics
Elevator Manufacturing
Defense & Space Manufacturing
Computers & Electronics / Industrial Machinery
Motor Vehicle Manufacturing
Food and Beverages
Distillery & Wines
Beverages
Shipping
Logistics
Mobility (EV / Public Transport)
Energy & Utilities
Hospitality
Digital Gaming Platforms
SportsTech with AI
Public Safety - Explosives
Public Safety - Firefighting
Public Safety - Surveillance
Public Safety - Others
Media Platforms
City Operations
Airlines & Aviation
Defense Warfare & Drones
Robotics Engineering
Drones Manufacturing
AI Labs for Colleges
AI MSP / Quantum / AGI Institutes
Retail Apparel and Fashion

Proceed Next