- Use Angular CLI for project scaffolding, component generation, and development tasks. This ensures consistency and leverages Angular's best practices out of the box.
- Follow a clear folder structure that separates features, shared modules, and core services. Organize code by feature rather than by type to improve maintainability.
- Enable strict mode in
tsconfig.json
to catch errors early and enforce type safety.
- Standalone Components: Angular uses standalone components, directives, and pipes by default. This simplifies development and reduces boilerplate. You no longer need to declare
standalone: true
—it is the default. - NgModules: While standalone is the default, NgModules are still supported for legacy code. Use
standalone: false
if you need to opt out. - Signals: Use Angular's new signals API for local state management and reactivity. Prefer signals over external state libraries for simple state needs.
- Follow the Angular Style Guide for naming conventions, file organization, and code formatting.
- Use TypeScript features such as interfaces, generics, and type annotations to improve code clarity and safety.
- Prefer
const
andlet
overvar
for variable declarations. Useconst
when values do not change. - Avoid using the
any
type. Always specify explicit types for variables, function parameters, and return values.
- Keep components small and focused. Each component should have a single responsibility.
- Use OnPush change detection to optimize performance, especially for presentational (dumb) components.
- Leverage Angular's built-in directives like
*ngFor
and*ngIf
efficiently. Avoid heavy logic inside templates. - Adopt self-closing tags for void elements to keep templates clean. Use the migration tool if needed.
- Use Signals for local state: Signals are now the recommended way to manage local and derived state in Angular 19.2.0. Use
signal
,computed
, andeffect
from@angular/core
. - For complex state, consider NgRx or NGXS: For large-scale applications, use established state management libraries.
- Avoid nested subscriptions: Use RxJS operators like
combineLatest
orwithLatestFrom
instead of subscribing within subscriptions.
- Choose the right form approach: Use template-driven forms for simple cases and reactive forms for complex scenarios.
- Leverage new form features: Angular 19.2.0 supports type sets in validators for more flexible validation.
- Keep form logic in the component and avoid putting business logic in templates.
- Use the new
httpResource
API for streamlined HTTP data fetching and resource management. - Cache API calls where appropriate to improve performance and reduce network usage.
- Lazy load modules and components to reduce initial load time.
- Use trackBy with
*ngFor
to optimize list rendering. - Optimize change detection by using OnPush strategy and signals.
- Sanitize all user input to prevent XSS attacks.
- Use Angular's built-in security features for safe data binding and template rendering.
- Write unit tests for components, services, and pipes using Jasmine, Karma, or Jest.
- Use end-to-end testing tools like Cypress or Playwright for user flow validation.
- Run tests with AOT compilation for better reliability and performance.
- Document code and components with clear comments and README files.
- Use version control (Git) and follow the team's branching and commit message conventions.
- Participate in code reviews to maintain code quality and share knowledge.