Do you use standalone components?

Last updated by Anton Polkanov [SSW] 9 months ago.See history

Standalone components were introduced in Angular 14 and should be used instead of modules for every new component you create.

There is a number of advantages of using standalone components over modules as they:

  1. Reduce the amount of boilerplate code. They don't belong to a particular NgModule and don't have to be declared, so can be used in any part of the application
  2. Streamline component creation
  3. Allow to lazy-load the component without using an NgModule
  4. Flatten the learning curve for new developer as the concept of NgModules is off the table

To make a component standalone, set standalone: true

  standalone: true,
  selector: 'my-component',
  imports: [FooComponent],
  template: `
export class MyComponent {
  // component logic
We open source. Powered by GitHub