angular / angular-cli

CLI tool for Angular
https://cli.angular.dev
MIT License
26.79k stars 11.98k forks source link

"ng destroy component" doesn't remove the "import" statement from "app.module.ts", nor does it remove the component from the declarations array #1788

Closed NgxDev closed 8 years ago

NgxDev commented 8 years ago

When generating a component, the CLI makes necessary changes to "app.module.ts". I would expect that destroying a component should accomplish the opposite (remove files, remove that import statement and also remove that component from the declarations array on the @NgModule decorator).

angular-cli: 1.0.0-beta.11-webpack.2
node: 6.4.0
os: win32 x64
filipesilva commented 8 years ago

We don't really support destroying generated stuff, it's a remnant from ember-cli functionality. We'll try to remove it from ng help in https://github.com/angular/angular-cli/issues/1807.

timondavis commented 8 years ago

It seems to me that if the automated inclusion routine edits a given file, the automation removal routine should remove the edits on that same file. Either that, or the deletion routine should be scrapped. Inconsistent behavior will likely lead to confusion and not convenience.

elvisbegovic commented 8 years ago

@filipesilva why not add support ng destroy ? it's realy helpfull and it works just import from *.module.ts doesn't removed, will be nice to get a look here

filipesilva commented 8 years ago

It's more than just removing imports. There's usually more code than that added, and users might have modified it further after the generator did it's job. So we can't determine well what should be removed.

elvisbegovic commented 8 years ago

ok then you can destroy only if you create by error without and modification, as me 5min ago. I just created and directly ng destroy c header ... by this way only import doesn't work ! but anyway this is "nice to have feature" better perform angular-cli command because it's a little slow right now,

thanks for reply

inigopascall commented 8 years ago

I agree, it's a pain in the ass when you create the component with an error in the name and just want to immediately delete...

tomeastmanjr commented 7 years ago

100% agree. I just created a test component for testing using $ ng g component chartJS-charts I did not pay attention to when it saved as chart-js-charts. I then immediately created a new component using $ ng g component chartJS-charts/bar-charts This created a new fileless component actually titled chartJS-charts with a child/sub component titled bar-charts.

All I want to do is go remove one of the duplicates in an automated way so that I can keep clean organization going forward.

judasane commented 6 years ago

100% agree too. It would be really helpful to have a command to destroy components, so we can delete them keeping the code clean

navidRashik commented 6 years ago

I would like to see this feature in future !!!

angular-automatic-lock-bot[bot] commented 5 years ago

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.