Last updated: Apr 4, 2024
Reading time·3 min
Deleting a component is not supported with the Angular CLI, so you have to do it manually.
To delete an Angular component:
In VS Code, you can right-click on the folder and select Delete or simply left-click the folder and press the Del key on your keyboard.
src/app/app.module.ts
file or the module in which you imported
the component.Remove the component from the declarations
array in your @NgModule
decorator.
Here is what my src/app/app.module.ts
file looks after I've deleted the
import statement and the declarations
entry.
I've written a detailed guide on how to search all files in Visual Studio Code.
Ctrl
+ Shift
+ F
(Windows and Linux).Cmd
+ Shift
+ F
(macOS).If you find any import statements and references to the deleted component, make sure to remove them.
If you get an error, restart your code editor and your server.
--dry-run
option when issuing the ng generate
commandUse the --dry-run
option if you need to test the output of the ng generate
command when creating a component.
The option enables you to view the output of the ng generate
command without
writing files to the disk.
npx ng generate component example --dry-run
The command lists the files that would get created and updated if you run the
ng generate
command without the --dry-run
option.
app.module.ts
file because the command automatically imports the generated component and adds it to the declarations
array.Deleting a component via the Angular CLI is not supported, so you have to manually delete the component's folder and any import statements and references.
You can learn more about the related topics by checking out the following tutorials: