2 A standalone future
This chapter covers
- Using Angular components, directives, and pipes without
NgModule
s - Structuring applications without
NgModule
s - Routing and lazy-loading of standalone components
- Migrating existing applications to standalone
In the previous chapter, we learned about recent developments in Angular and laid out a learning plan for this book. We also created a project and already encountered standalone components. Now it is the time to explore one of the new capabilities of modern Angular, building applications without NgModule
s, colloquially known as standalones, and understand both the benefits and shortcomings of this approach. To do so, we first need to examine the reasons why teams are making a switch away from NgModule
s in a more profound way.
2.1 Why abandon NgModules?
As we know, before Angular v14, all Angular applications used NgModule
s to be able to run. It was the very first Angular concept new developers learned about, and it was the glue that held Angular applications together; components, in contrast, were specifically not that glue. In this context, NgModule
s were a fundamental part of the framework. So what changed? Why change so drastically? It turns out not everyone was happy with NgModule
s.
Before we move on, we need to understand several key points about both modules and standalones: