Files
MyAiConfiguration/shared/rules/angular/references/templates-and-styling.md
T
Julian LechnerandClaude Opus 5.5 b6c33780c3 docs(rules): update TypeScript and Angular rules for TS 7 and trim duplicates
TypeScript 7.0 ships the native compiler as tsc and drops options
deprecated in 6.0. Angular 22 still requires TypeScript >=6.0.0 <6.1.0,
so both rule sets now warn against moving Angular projects to TS 7, and
the Angular index asks to check the Angular version first.

TypeScript runtime safety adds error handling (Error objects only,
cause chaining, unknown in catch, one error model per layer, no
swallowed errors) plus exact decimals for money, ISO 8601 UTC dates, and
Intl formatting. Angular adds per-route SSR render modes, a global
ErrorHandler with provideBrowserGlobalErrorListeners, and translatable
text with locale-aware formatting.

Generic guidance that the TypeScript, refactoring, and UI/UX rules
already cover is removed from the Angular rules, which shrink by about
7.5 percent despite the additions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 10:08:25 +01:00

1.4 KiB

Angular Templates and Styling

Apply these rules when writing Angular templates, control flow, or component styles. Load the UI/UX rules for visual design.

Templates

  • Keep template expressions short. Reading signals and computed values is correct; do not call other methods that compute or allocate from templates, and move complex conditions into computed state or a pure pipe.
  • Use built-in control flow (@if, @for, @switch) in new code.
  • In @for, track a stable unique key such as track item.id; use $index only for static lists that never reorder. For legacy *ngFor, supply trackBy.
  • Split large or deeply nested templates into focused components, and avoid unnecessary DOM elements.
  • Use semantic HTML and native elements before custom implementations; see the accessibility section of the Angular security and accessibility rule.
  • Keep user-facing text translatable with the project's i18n approach, such as i18n attributes and $localize, and format dates, numbers, and currencies with locale-aware pipes instead of hand-built strings.

Styling

  • Keep styles scoped to the component and follow the project's styling strategy; avoid unnecessary global CSS and mixing styling approaches.
  • Prefer design tokens and shared styles over magic values. Avoid excessive specificity, !important, and selectors that depend on fragile DOM structure.