Skip to the page

Components and templates · core

Standalone components and NgModules

A standalone component lists its own imports, so each file shows what it uses. NgModules are the older way and still appear in old code and in interviews.

The notes

What you must know

  • An NgModule set the compilation scope: which components, directives and pipes a template may use. It also carried providers.
  • A standalone component has its own imports array. Its dependencies are visible in one file.
  • Standalone components are the default since v19 (facts.md). In new code you do not write standalone: true.
  • Lazy loading is simpler with standalone: loadComponent loads one component without a module.
  • Tree shaking and @defer work better when dependencies are explicit per component.
  • Standalone and NgModule code can live together. A standalone component can import an NgModule, and an NgModule can import a standalone component.
  • Say clearly which is older: NgModules are the old style. Modern apps start with bootstrapApplication and provideRouter, not AppModule.

The red pen

Common traps: mistake → fix

  • Mistake: NgModules are removed from Angular

    Fix: they still work and old apps use them; new code just does not need them.

  • Mistake: A standalone component needs a module to be used in a template

    Fix: it goes into the imports of the component that uses it.

Easy to hard

Questions interviewers ask, easy to hard

  1. What is the difference between a standalone component and one declared in an NgModule?
  2. Where do you register a pipe that a standalone component uses?
  3. How does lazy loading change when you drop NgModules?
  4. Your company has a big NgModule app. How would you move it to standalone?

Practise

Practise with these questions

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview