What is the best way to delete a component with CLI

后端 未结 14 1492
时光取名叫无心
时光取名叫无心 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 18:54

    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).

    1. It creates a separate folder named demoComponent (ng g c demoComponent).
    2. It generate HTML,CSS,ts and a spec file dedicated to demoComponent.
    3. Also, It adds dependency inside app.module.ts file to add that component to your project.

    so do it in reverse order

    1. Remove Dependency from app.module.ts
    2. Delete that component folder.

    when removing the dependency you have to do two things.

    1. Remove the import line reference from app.module.ts file.
    2. Remove the component declaration from @NgModule declaration array in app.module.ts.

提交回复
热议问题