43

I am working on angular2 for my new project, newly with this technology. I have set-up my project with angular CLI (Reference site https://github.com/angular/angular-cli). I have created 4 components using command ng generate component my-new-component For testing purpose, created one component app-testing, need to remove that component from my project. Else need to rename for that component. I have tried several like. ng destroy component app-testing but showing error The destroy command is not supported by Angular-CLI., Please help me with solution. Thanks in advance.

Luca
  • 9,259
  • 5
  • 46
  • 59
kishan kurivella
  • 589
  • 4
  • 7
  • 19

10 Answers10

33

I had the same problems and it seems that they removed the destroy command from the CLI and you need to do it manually by deleting or renaming the according folders/files and imports, which is really a laborious task.

https://github.com/angular/angular-cli/issues/900 https://github.com/angular/angular-cli/issues/1788

Carsten H
  • 831
  • 15
  • 32
  • 10
    would be useful to see them adding in an automated command again. Whole point of the CLI is to make your life easier (rather than blocking you from using commands). – Luke Brown Mar 07 '17 at 15:47
  • see my answer... there are better ways to "undo" now. – FlavorScape Oct 18 '18 at 23:06
  • better is to use --dry-run for example ng g c componentName --dry-run command it will show you what component is going to create and at what location and if you are ok then run the same command without --dry-run – Engineer Jun 30 '20 at 12:27
10

You can delete any component by removing all its lines from app.module.ts . Its working fine for me.

sumit gupta
  • 101
  • 1
  • 2
2

version control is your friend here, do a diff or equivalent and you should see what's been added/modified.

In fact, removing the component folder might not be enough; with Angular-CLI v1.0, the command ng generate component my-new-component also edits your app.module.ts file by adding the respective import line and the component to the providers array.

Luca
  • 9,259
  • 5
  • 46
  • 59
2

You should remove your component manually, that is...

[name].component.ts
[name].component.html  // if you've used templateUrl in your component
[name].component.spec.ts  // if you've created test file
[name].component.[css or scss]  // if you've used styleUrls in your component

If you have all that files in a folder, delete the folder directly.

Then you need to go to the module which use that component and delete

import { [component_name] } from ...

and the component on the declarations array

That's all. Hope that helps

Cruz Jurado
  • 181
  • 1
  • 8
1

No As of now you can't do this by any command. You've to remove Manually from app.module.ts and app.routing.module.ts if you're using Angular 5

Hidayt Rahman
  • 2,490
  • 26
  • 32
0

I had the same issue, couldn't find a right solution so I have manually deleted the component folder and then updated the app.module.ts file (removed the references to the deleted component) and it worked for me.

Jayampathy Wijesena
  • 1,670
  • 1
  • 18
  • 26
-1

I tried ng remove component Comp_Name also ng distroy component but it is not yet supported by angular so the best option for now is to manually remove it from the folder structure.

Asif Karim Bherani
  • 1,023
  • 1
  • 13
  • 25
-1

This is the NPM known Issue for windows that NPM is pretty much unusable under Windows. This is of course related to the path size limitations.

https://github.com/npm/npm/issues/5641

My main concern here is that there are no mention of these issues when installing node or npm via the website. Not being able to install prime packages makes npm fundamentally unusable for windows.

eli
  • 8,571
  • 4
  • 30
  • 40
-4

Try to uninstall angular and then reinstall

npm uninstall --save @angular/(then whatever component you want deleted)

after that, a box with babyblue color border will appear with suggestion to update and install angular back up.

N Ouk
  • 1
  • 5
-8

There's the --dry-run flag which will allow you to preview the changes, and/or you can use the Angular Console App to generate the cli flags for you, using their easy GUI. It auto-previews everything before you commit to it.

FlavorScape
  • 13,301
  • 12
  • 75
  • 117