Thursday, February 15, 2024

Standalone Components in Angular

Standalone Components in Angular

A standalone component is a type of component that doesn’t belong to any specific Angular module.Before Angular version 14, when you created a component, you typically had to include it in the declaration array of a module; otherwise, Angular would throw an error during compilation.Standalone components are independent units that can be instantiated and used anywhere within an Angular application, regardless of the module structure. Standalone components can be useful for creating reusable UI elements or utility functions that are not specific to any module.

In this post, we'll explore standalone components in Angular and how to create them with a detailed example.

Creating a Standalone Component

First, make sure you're using Angular version 14. To create a component on its own, use the --standalone option with the command ng generate component.

ng g c component_name  --standalone
^ Scroll to Top