DEV Community

Manthan Ankolekar
Manthan Ankolekar

Posted on

7

Easy steps to migrate all Angular components to standalone

To make all components in your Angular project standalone, you can use the following steps:

  1. Update your angular.json file to set the standalone flag to true for all component schematics:
// angular.json
{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "my-app": {
      "projectType": "application",
      "schematics": {
        "@schematics/angular:component": {
          "standalone": true
        }
      }
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Run the following command to migrate all existing components to standalone:

ng g @angular/core:standalone --all
Enter fullscreen mode Exit fullscreen mode

This will add the standalone: true flag to all component decorators and update the component imports as needed.

Verify that your application builds and runs correctly.
Once you have made all components standalone, you can remove any unnecessary NgModules from your application.

Here is an example of how to remove an NgModule:

  1. Open the NgModule file in a text editor.
  2. If the NgModule does not bootstrap a component, you can simply delete the file.
  3. If the NgModule does bootstrap a component, you need to move the component declaration to the main.ts file.

Once you have removed all unnecessary NgModules, you will have a fully standalone Angular application.

Please note that the ng g @angular/core:standalone --all command may not be able to migrate all components perfectly. You may need to make manual changes to some components.

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

Top comments (0)

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, cherished by the supportive DEV Community. Coders of every background are encouraged to bring their perspectives and bolster our collective wisdom.

A sincere “thank you” often brightens someone’s day—share yours in the comments below!

On DEV, the act of sharing knowledge eases our journey and forges stronger community ties. Found value in this? A quick thank-you to the author can make a world of difference.

Okay