Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

What is the best way to delete a component with CLI

I tried using "ng destroy component foo" and it tells me "The destroy command is not supported by Angular-CLI"

How do we properly delete components with Angular CLI?
by

3 Answers

rahul07
destroy or something similar may come to the CLI, but it is not a primary focus at this time. So you will need to do this manually.

Delete the component directory (assuming you didn't use --flat) and then remove it from the NgModule in which it is declared.

If you are unsure of what to do, I suggest you have a "clean" app meaning no current git changes. Then generate a component and see what is changed in the repo so you can backtrack from there what you will need to do to delete a component.
RoliMishra
I am not sure if it is the best way, but it worked for me.

1) First, I deleted the component folder.
2) Then, I cleared app.module.ts, app.component.ts & app.component.html of the imports and declarations related to the component I wanted to delete.
3) Similarly, I cleared main.ts.
I just saved and refreshed the app and it worked.
pankajshivnani123
Currently Angular CLI doesn't support an option to remove the component, you need to do it manually.

Remove import references for every component from app.module
Delete component folders.
You also need to remove the component declaration from @NgModule declaration array in app.module.ts file

Login / Signup to Answer the Question.