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
I needed to delete an Angular 6 directive whose spec file was erroneous. Even after deleting the offending files, removing all references to it and rebuilding the app, TS was still reporting the same error. What worked for me was restarting Visual Studio - this cleared the error and all traces of the old unwanted directive.
Using Visual Studio Code, delete the component folder and see in the Project Explorer(left hand side) the files that colors Red that means the files are affected and produced errors. Open each files and remove the code that uses the component.
Answer for Angular 2+
Remove component from imports and declaration array
of app.modules.ts.
Second check its reference is added in other module, if yes then remove it and
finally delete that component Manually
from app and you are done.
Or you can do it in reverse order also.
I am not sure if it is the best way, but it worked for me.
I just saved and refreshed the app and it worked.
Since it is not yet supported using angular CLI
so here is the possible way, before that please observe what happens when you create a component/service using CLI (ex. ng g c demoComponent
).
demoComponent
(ng g c demoComponent
).HTML,CSS,ts
and a spec
file dedicated to demoComponent.so do it in reverse order
app.module.ts
when removing the dependency you have to do two things.