Angular¶
Scope: web apps built with Angular 22, the current major version (released on 3 June 2026), with standalone components, signals, the Angular CLI and, where used, Angular's server-side rendering. Angular 21 still gets critical and security fixes in long-term support until June 2027; Angular 20's support ended on 28 November 2026, and older versions are no longer supported. From version 22 on, a new major version ships every 12 months instead of every 6 (Angular, Versioning and releases). Framework-independent rules for accessibility, performance, security and testing (WEB-*) are in Web front end, and the compiler settings (TS-*) in TypeScript. The Node.js server that renders pages for server-side rendering is backend code, so the Node.js and Security guidelines also apply to it.
Entries are sorted by score from 1 to 10 (criteria): 9โ10 start here or strongly recommended, 6โ8 recommended, 1โ5 further reading or conditional.
Adopted references¶
- 9 Angular documentation: the baseline. The essentials and in-depth guides to components, templates, signals, dependency injection, routing, forms, the HTTP client, server-side and hybrid rendering, testing and internationalization, and the best-practice pages on security, accessibility and performance.
- 8 Angular coding style guide: the official Angular-specific conventions: file names that match the class inside, such as
user-profile.tsforUserProfile, one concept per file, folders by feature instead of by type,inject()instead of constructor injection, and components that focus on presentation. - 8 Angular, Security: Angular's XSS model and sanitization, Content Security Policy and Trusted Types, XSRF protection in
HttpClient, and, for server-side rendering, allowed host names and trusted proxy headers against server-side request forgery. - 8 Angular, Server-side and hybrid rendering: choosing a rendering mode, server routes with a render mode per route, prerendering, the HTTP transfer cache, and writing components that also run on the server.
- 7 Angular, Signals: writable and computed signals, reactive contexts and read-only signals, with guides to
linkedSignal, resources and effects. - 7 Angular, Performance: when to use each loading technique (lazy-loaded routes,
@defer, lazy-loaded services, image optimization and server-side rendering) and each runtime technique (zoneless change detection, slow computations, skipping component subtrees and profiling). - 7 Angular, Versioning and releases: the release schedule, the support window of 12 months active and 12 months long-term support, the supported versions, the deprecation policy and the supported update paths.
- 7 Angular Update Guide: step-by-step instructions for an update between two versions, filtered by the app's complexity and dependencies such as Angular Material.
- 7 Angular, Accessibility: ARIA bindings, building on native elements, focus management and active links after routing, and the accessible components in Angular Material, the CDK and Angular Aria.
- 7 Angular, Testing: unit tests with Vitest, the default runner for new projects, tests in a real browser, code coverage, CI, and guides to testing components, services, routing and HTTP and to component harnesses.
- 6 Angular CLI: creating, building, serving, testing and updating apps with
ng, plus builders and schematics. The esbuild-based application builder is the default, and the webpack-basedbrowserbuilder is deprecated.
Key rules¶
Components and reactivity¶
- 7
ANGULAR-1Keep the current defaults in new code: standalone components,OnPushchange detection and zoneless change detection. Don't setstandalone: false,ChangeDetectionStrategy.EagerorprovideZoneChangeDetection(). The Angular team recommends standalone components instead of NgModules for all new code, components areOnPushby default since version 22, and apps are zoneless by default since version 21. (Angular, NgModules, Skipping component subtrees: using OnPush, Zoneless: enabling zoneless) - 7
ANGULAR-2Derive state withcomputed(), or withlinkedSignal()when the user can also set it, and useeffect()only to sync signals with APIs that aren't reactive, such as storage, logging, or a canvas or third-party UI library. Copying one signal into another with an effect can causeExpressionChangedAfterItHasBeenCheckederrors, circular updates and extra change detection. (Angular, Use cases for effects, Dependent state with linkedSignal) - 6
ANGULAR-3Declare inputs, outputs and queries with the signal-based functions, such asinput(),output(),model()andviewChild(), and name outputs in camelCase, without anonprefix and without the name of a DOM event such asclick. The decorator-based APIs remain supported, but the Angular team recommends the functions for new projects. (Angular, Accepting data with input properties, Outputs: choosing event names, Queries) - 6
ANGULAR-4Use the built-in control flow (@if,@forand@switch) instead of the deprecated*ngIf,*ngForand*ngSwitch, and give every@foratrackexpression with a property that uniquely identifies the item, such as its ID. Track by$indexonly for collections that never change, and avoid tracking the item itself, which can make updates much slower. (Angular, Why is track in @for blocks important?, NgIf)
Services and state¶
- 7
ANGULAR-5Keep components focused on presentation, and move business logic, data access and state that several components share into services. Keep that state in private writable signals, and expose it as read-only signals, withasReadonly()orcomputed(), plus methods that change it. (Angular style guide, Keep components and directives focused on presentation, Creating and using services, Signals: converting writable signals to readonly) - 6
ANGULAR-6Declare app-wide services with@Service(), or with@Injectable({providedIn: 'root'})before Angular 22, inject dependencies withinject(), and provide a service in a route'sprovidersinstead when only one feature uses it. Root services are tree-shakable singletons. Route providers load with the feature's lazy-loaded routes, and its components, guards and resolvers share them. (Angular, When to use @Service vs @Injectable, Style guide: prefer the inject function, Route providers) - 6
ANGULAR-7Read data that depends on signals withhttpResource(), convert Observables that templates read withtoSignal(), and send changes, such asPOSTandPUTrequests, withHttpClientdirectly. GivehttpResource()aparsefunction, such as a Zod schema, to check responses at run time (TS-8), and put cross-cutting concerns, such as retries, caching and logging, in functional interceptors, which behave more predictably than DI-based ones. (Angular, Using httpResource, Response parsing and validation, toSignal, Interceptors)
Routing and rendering¶
- 7
ANGULAR-8Lazy-load every route except the main landing pages withloadComponentorloadChildren, and wrap heavy components that aren't visible on the first render in@deferblocks. Don't defer content in the initial viewport, which causes layout shifts, and give nested@deferblocks different triggers. This is how an Angular app appliesWEB-5. (Angular, Should I use an eager or a lazy route?, Lazily loaded components and routes, Best practices for deferring views) - 7
ANGULAR-9In server-rendered apps, set a render mode for each route in the server routes:RenderMode.Prerenderfor pages that are the same for every user,RenderMode.Serverfor pages with user-specific data, andRenderMode.Clientonly where load performance and SEO matter less. For hydration, render the same DOM on the server and in the browser: run browser-only code inafterNextRender(), and don't accessdocumentor change the DOM with native APIs. (Angular, Server routing, Choosing a rendering mode, Authoring server-compatible components, Hydration: constraints) - 6
ANGULAR-10Set thetitleproperty of every route, and move focus to the main content in a listener for the router'sNavigationEndevent. Angular sets the page title when the route activates, and without the listener focus can fall back to thebodyelement. This is how Angular appliesWEB-22. (Angular, Page titles, Accessibility: focus management after navigation)
Security¶
- 9
ANGULAR-11Never use route guards as access control: check authorization on the server for every request. Guards only decide what the browser shows, and users can change any JavaScript that runs in their browser. This appliesSEC-1in Security, and Authentication covers sessions and tokens. (Angular, Control route access with guards) - 9
ANGULAR-12Never build Angular templates from user input: ship only templates that the CLI compiles ahead of time, and don't generate Angular templates with a server-side templating language. Angular treats templates as trusted, executable code, so injected template syntax gives an attacker full control of the app. (Angular, Security: XSS security model, Use the AOT template compiler, Server-side XSS protection) - 9
ANGULAR-13Insert untrusted values through template bindings, so that Angular sanitizes them, never pass them to theDomSanitizer.bypassSecurityTrust*()methods, and don't write to the DOM throughElementRef.nativeElementordocument. Where direct DOM access can't be avoided, sanitize values withDomSanitizer.sanitize()and the matchingSecurityContext. This is how an Angular app appliesWEB-8. (Angular, Sanitization and security contexts, Trusting safe values, Direct use of the DOM APIs) - 9
ANGULAR-14Never put secrets, such as API keys, in the files insrc/environments/: the build bundles them into the client, where anyone who loads the page can read them. Keep secrets on a server, for example behind a proxy. This appliesSEC-11. (Angular, Build environments) - 7
ANGULAR-15Send a Content Security Policy with a unique, unpredictable nonce for each response, and pass the nonce to Angular with thengCspNonceattribute or theCSP_NONCEtoken. On static hosting that can't add a nonce, turn onautoCspor avoid inline scripts, instead of hard-coding a nonce. Also enforce Trusted Types with Angular'sangularpolicy. This is how an Angular app appliesWEB-10. (Angular, Content security policy, Hash inline scripts with autoCsp, Enforcing Trusted Types)
Build, tooling and upgrades¶
- 8
ANGULAR-16Run a major version that is still supported, update withng updateone major version at a time, and plan each yearly major update before your version's long-term support ends.ng updatealso runs the code migrations for the new version. This appliesSEC-17. (Angular, Actively supported versions, Breaking change policy and update paths, ng update) - 7
ANGULAR-17Keep strict template type checking on (strictTemplates, the default) together with TypeScript'sstrict(TS-1), and make the extended diagnostics fail the build by setting theirdefaultCategorytoerror. Extended diagnostics find mistakes such as signals that aren't called in interpolations andtrackfunctions that aren't called, but by default they are only warnings. (Angular, Template type checking: strict mode, Extended diagnostics: configuration)
Testing¶
- 6
ANGULAR-18Test components the way users use them, and let Angular schedule change detection: drive shared UI components through component harnesses, awaitfixture.whenStable()instead of callingfixture.detectChanges(), and answer HTTP requests withHttpTestingController, then callverify(). These are Angular's tools forWEB-14andWEB-20. (Angular, Component harnesses overview, Zoneless: using zoneless in TestBed, Testing HttpClient)
How to enforce¶
Tools that check the key rules above automatically, in CI, the IDE or a commit hook. "Partly" means the tool covers only some of what the rule asks.
- 7 Angular extended diagnostics: compiler checks that run with strict template type checking, such as NG8109 for signals that aren't called in interpolations and NG8115 for
trackfunctions that aren't called. WithdefaultCategoryset toerror,ng buildfails on them. ThestrictStandalonecompiler option also reports every component, directive or pipe that isn't standalone. ChecksANGULAR-17, and partlyANGULAR-1. - 6 angular-eslint: ESLint rules for Angular code and templates, set up with
ng add angular-eslint. The recommended configs includeprefer-standalone,prefer-on-push-component-change-detection, which flags components that opt out of the defaultOnPush,prefer-inject,no-output-native,no-output-on-prefixandtemplate/prefer-control-flow. Turn onprefer-signalsandprefer-output-emitter-reffor signal-based inputs, queries and outputs, andprefer-service-decoratoron Angular 22. Partly checksANGULAR-1,ANGULAR-3,ANGULAR-4andANGULAR-6. - 6 Angular CLI size budgets:
ng buildfails when the initial bundle, a named lazy-loaded bundle or another budget type grows past itsmaximumError. Partly checksANGULAR-8. - 5 Semgrep
angular-bypasssecuritytrust: flags calls to thebypassSecurityTrust*()methods whose argument comes from a string parameter of the surrounding function and wasn't sanitized, for example with DOMPurify. Partly checksANGULAR-13.
Tutorials and further reading¶
- 7 Learn Angular: the official interactive tutorial, which teaches Angular's building blocks step by step in the browser.
- 6 Build your first Angular app (Angular): the official tutorial for building a small app locally with the CLI, also available as a video course.
- 6 Learn Angular signals (Angular): an interactive tutorial on signals and building reactive apps with them.