Angular · Migration · Frontend · TypeScript

Migrating from NgModules to Standalone Components in Angular

Moving an existing Angular app from NgModules to standalone components: the official schematic, bootstrapApplication, providers, lazy loading and pitfalls.

Sander Yazıcıoğlu Published: 2 min read Türkçe oku

Migrating from NgModules to Standalone Components in Angular

Standalone components made NgModules, for years one of the hardest concepts for Angular newcomers, optional, and became the default in Angular 19. In a large, older app this migration can look scary, but Angular's official schematic does most of the work. This article walks through it in safe steps.

What standalone buys you

  • Less boilerplate: each component lists its dependencies in its own imports array; no more tracking which module exports what.
  • Better tree-shaking: unused components stay out of your bundles.
  • Simpler lazy loading: routing to a single component no longer requires a module.
@Component({
  selector: 'app-run-list',
  imports: [DatePipe, RouterLink, RunStatusBadge],
  template: `...`
})
export class RunListComponent {}

Prerequisite: a current version

Before migrating, the app should be on at least Angular 15, ideally the current version. I cover upgrading in the Angular upgrade guide.

The official schematic: three steps

ng generate @angular/core:standalone

The schematic asks you to pick a mode, and you are meant to run each mode in order:

  1. Convert all components, directives and pipes to standalone: adds imports to components and updates module declarations.
  2. Remove unnecessary NgModule classes: deletes modules that no longer do anything.
  3. Bootstrap the application using standalone APIs: switches from AppModule to bootstrapApplication.

After each step, build, run the tests and commit. If something breaks, you know which step did it.

The new bootstrap

bootstrapApplication(AppComponent, {
  providers: [
    provideRouter(routes, withComponentInputBinding()),
    provideHttpClient(withInterceptors([authInterceptor])),
    provideAnimationsAsync()
  ]
});

provide... functions replace HttpClientModule, RouterModule.forRoot and friends. If you have class-based interceptors, withInterceptorsFromDi() keeps them working while you move to functional interceptors.

Lazy loading

export const routes: Routes = [
  { path: 'runs', loadComponent: () => import('./runs/run-list.component').then(m => m.RunListComponent) },
  { path: 'admin', loadChildren: () => import('./admin/admin.routes').then(m => m.ADMIN_ROUTES) }
];

Declaring feature-specific services with route-level providers replaces the providers array of feature modules.

Pitfalls

  • Shared modules: if a giant SharedModule exports everything, the schematic may add it to components' imports. Over time import the pieces you actually use directly, or you lose much of the tree-shaking gain.
  • Third-party libraries: older libraries may still export NgModules; adding a module to a standalone component's imports is fine.
  • Tests: in TestBed.configureTestingModule the component moves from declarations to imports. The schematic updates most tests, but some need manual fixes.
  • Circular imports: two components importing each other fail to compile; extract the shared part into its own component.

Measure

Compare the main bundle size and initial load time before and after. As you break up shared modules, you'll see the bundle shrink.

Conclusion

The standalone migration is not a rewrite but a modernisation in three safe steps with the official schematic. You end up with more readable components, simpler routes and smaller bundles.

Angular Performance with OnPush and Change Detection

December 2, 2026 · 2 min read

Angular Performance with OnPush and Change Detection

Default versus OnPush change detection in Angular, what triggers an OnPush check, speeding up large lists with track and trackBy, and the most common mistakes.

AngularPerformanceFrontendTypeScript

All articles →