Search code examples
angulartypescriptcomponentsangular-module

Best Practices: Standalone Components vs. Modules in Angular 14


I'm seeking clarification on the best practices regarding the usage of standalone components and modules in Angular 14. Given the introduction of standalone components as a new concept in Angular, I'm looking for factual guidance supported by citations or references.

I've created a new whole app only using standalone components with lazy loading routes, and everything works perfectly. Here the repo: https://github.com/Ismaestro/angular-example-app

However, I'm curious if this indicates a potential shift towards standalone components rendering NgModules obsolete.

Could someone provide evidence-based insights into the advantages and disadvantages of employing standalone components versus modules in Angular 14?

Thank you for your contributions.


Solution

  • Standalone components are not mandatory and will never be, there is no rule when to use them. However, Angular Architects recommend to always use Standalone components at least for new components you create. They are simply more treeshakeable and less boiler. You can mix standalone components and modules also.

    For the mentioned recommendation of the Angular Architects, you can also watch the Webinar from last Monday: https://www.youtube.com/watch?v=9rj8kR0q0c8