What is the best way to delete a component with CLI

后端 未结 14 1400
时光取名叫无心
时光取名叫无心 2020-12-22 18:35

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

相关标签:
14条回答
  • 2020-12-22 19:05

    This is not supported by Angular CLI and they are in no mood to include it any time soon.

    Here is the link to the actual created issue - https://github.com/angular/angular-cli/issues/1776

    And a screenshot of the solution from the officials -

    0 讨论(0)
  • 2020-12-22 19:07

    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.

    Update

    If you're just experimenting about what you want to generate, you can use the --dry-run flag to not produce any files on disk, just see the updated file list.

    0 讨论(0)
提交回复
热议问题