Standalone components let you build an entire Angular application without ever writing an NgModule. This lesson covers how they work and how a fully standalone app is bootstrapped.
What Makes a Component Standalone?
A standalone component declares its own dependencies (other components, directives, pipes) directly through an imports array on its own @Component decorator, rather than relying on a surrounding NgModule to provide them.
Since Angular 17, standalone is the default when you generate a new component with the CLI, and the Angular team recommends it for all new projects going forward.
ng generate component (standalone by default in modern CLI)
Importing Only What a Component Needs
Standalone components make dependencies explicit and local: a component only imports the specific directives, pipes, or other components its own template actually uses, rather than gaining access to everything a large shared module happens to export.
Using the modern @for control flow, this component wouldn't even need NgFor imported at all.
Standalone Directives and Pipes
Directives and pipes can also be standalone (and are, by default, in modern Angular), meaning they're imported directly wherever they're used, exactly like standalone components.
Standalone components can be gradually introduced into an existing NgModule-based codebase: an NgModule can import a standalone component, and a standalone component can, in turn, import an existing NgModule if it needs something that module exports.
@NgModule({
declarations: [LegacyComponent],
imports: [NewStandaloneWidgetComponent], // standalone component imported into an NgModule
})
export class LegacyFeatureModule {}
Common Mistakes
Forgetting to import a directive, pipe, or child component a standalone component's template actually uses.
Assuming standalone components can't coexist with NgModules; they interoperate in both directions.
Manually importing large NgModules into a standalone component when only a specific standalone piece is actually needed.
Using bootstrapModule alongside standalone components without a root AppModule, standalone apps should use bootstrapApplication.
Key Takeaways
Standalone components declare their own dependencies via an imports array, no NgModule required.
bootstrapApplication() and provideX() functions replace the root module and NgModule-based service registration.
Directives and pipes can also be standalone, imported directly wherever they're used.
Standalone components and NgModules interoperate, enabling gradual migration of existing codebases.
Pro Tip
When migrating an existing NgModule-based app, start by converting leaf components (ones with few dependents) to standalone first, working inward toward shared/core components, this minimizes the blast radius of each migration step.
You now understand standalone components. Next, learn about Lazy Loading to split your application into smaller, on-demand chunks.