2 A standalone future
This chapter covers
- Using Angular components, directives, and pipes without
NgModules - Structuring applications without
NgModules - 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 NgModules, 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 NgModules in a more profound way.
2.1 Why abandon NgModules?
As we know, before Angular v14, all Angular applications used NgModules 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, NgModules were a fundamental part of the framework. So what changed? Why change so drastically? It turns out not everyone was happy with NgModules.
Before we move on, we need to understand several key points about both modules and standalones: