What is the best way to delete a component with CLI












136















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 CLI?










share|improve this question



























    136















    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 CLI?










    share|improve this question

























      136












      136








      136


      19






      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 CLI?










      share|improve this question














      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 CLI?







      angular angular-cli






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 28 '16 at 2:54









      Jus10Jus10

      1,63221244




      1,63221244
























          11 Answers
          11






          active

          oldest

          votes


















          104














          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.






          share|improve this answer

































            87















            1. Delete the folder containing this component.

            2. In the app.module.ts remove the import statement for this component and remove its name from the declaration section of @NgModule

            3. Remove the line with the export statement for this component from index.ts.






            share|improve this answer



















            • 8





              where is index.ts ? Thanks

              – Shane G
              May 10 '17 at 20:12






            • 31





              in the latest versions of CLI they don't generate it.

              – Yakov Fain
              May 11 '17 at 0:08






            • 3





              I think one more step is missing... run ng serve again, isn't it?

              – gsalgadotoledo
              Jul 22 '17 at 1:08











            • index.ts? Not in 5

              – Andrew Koper
              Mar 11 '18 at 23:22











            • in Angular6, need to remove the import statement from app-routing.module.ts

              – tyro
              Jul 5 '18 at 5:12



















            21














            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.






            share|improve this answer

































              8














              Currently Angular CLI doesn't support an option to remove the component, you need to do it manually.




              1. Remove import references for every component from app.module

              2. Delete component folders.






              share|improve this answer































                4














                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.






                share|improve this answer































                  4














                  I wrote a bash script that should automate the process written by Yakov Fain below. It can be called like ./removeComponent myComponentName This has only been tested with Angular 6



                  #!/bin/bash
                  if [ "$#" -ne 1 ]; then
                  echo "Input a component to delete"
                  exit 1
                  fi

                  # finds folder with component name and deletes
                  find . -type d -name $1 | xargs rm -rf

                  # removes lines referencing the component from app.module.ts
                  grep -v $1 app.module.ts > temp
                  mv temp app.module.ts

                  componentName=$1
                  componentName+="Component"

                  grep -v -i $componentName app.module.ts > temp
                  mv temp app.module.ts





                  share|improve this answer


























                  • Please add a note for me to change this if the angular cli changes in the future

                    – Aidan Grimshaw
                    Oct 8 '18 at 6:30



















                  2














                  I am not sure if it is the best way, but it worked for me.




                  • First, I deleted the component folder.

                  • Then, I cleared app.module.ts, app.component.ts & app.component.html of the imports and declarations related to the component I wanted to delete.

                  • Similarly, I cleared main.ts.


                  I just saved and refreshed the app and it worked.






                  share|improve this answer































                    1














                    From app.module.ts:




                    • erase import line for the specific component;

                    • erase its declaration from @NgModule;


                    Then delete the folder of the component you want to delete and its included files (.component.ts, .component.html, .component.css and .component.spec.ts).



                    Done.



                    -



                    I read people saying about erasing it from main.ts. You were not supposed to import it from there in the first place as it already imports AppModule, and AppModule is the one importing all the components you created.






                    share|improve this answer

































                      -1














                      First of all, remove component folder, which you have to delete
                      and then remove its entries which you have made in "ts" files.






                      share|improve this answer

































                        -1














                        If you looking for some command in CLI, Then ans is NO for now.
                        But you can do manually by deleting the component folder and all the references.






                        share|improve this answer































                          -1














                          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.






                          share|improve this answer
























                            protected by eyllanesc Jun 23 '18 at 0:17



                            Thank you for your interest in this question.
                            Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



                            Would you like to answer one of these unanswered questions instead?














                            11 Answers
                            11






                            active

                            oldest

                            votes








                            11 Answers
                            11






                            active

                            oldest

                            votes









                            active

                            oldest

                            votes






                            active

                            oldest

                            votes









                            104














                            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.






                            share|improve this answer






























                              104














                              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.






                              share|improve this answer




























                                104












                                104








                                104







                                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.






                                share|improve this answer















                                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.







                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited Jan 12 at 20:35









                                Liam

                                16.2k1676129




                                16.2k1676129










                                answered Dec 28 '16 at 3:13









                                BroccoBrocco

                                39.6k85271




                                39.6k85271

























                                    87















                                    1. Delete the folder containing this component.

                                    2. In the app.module.ts remove the import statement for this component and remove its name from the declaration section of @NgModule

                                    3. Remove the line with the export statement for this component from index.ts.






                                    share|improve this answer



















                                    • 8





                                      where is index.ts ? Thanks

                                      – Shane G
                                      May 10 '17 at 20:12






                                    • 31





                                      in the latest versions of CLI they don't generate it.

                                      – Yakov Fain
                                      May 11 '17 at 0:08






                                    • 3





                                      I think one more step is missing... run ng serve again, isn't it?

                                      – gsalgadotoledo
                                      Jul 22 '17 at 1:08











                                    • index.ts? Not in 5

                                      – Andrew Koper
                                      Mar 11 '18 at 23:22











                                    • in Angular6, need to remove the import statement from app-routing.module.ts

                                      – tyro
                                      Jul 5 '18 at 5:12
















                                    87















                                    1. Delete the folder containing this component.

                                    2. In the app.module.ts remove the import statement for this component and remove its name from the declaration section of @NgModule

                                    3. Remove the line with the export statement for this component from index.ts.






                                    share|improve this answer



















                                    • 8





                                      where is index.ts ? Thanks

                                      – Shane G
                                      May 10 '17 at 20:12






                                    • 31





                                      in the latest versions of CLI they don't generate it.

                                      – Yakov Fain
                                      May 11 '17 at 0:08






                                    • 3





                                      I think one more step is missing... run ng serve again, isn't it?

                                      – gsalgadotoledo
                                      Jul 22 '17 at 1:08











                                    • index.ts? Not in 5

                                      – Andrew Koper
                                      Mar 11 '18 at 23:22











                                    • in Angular6, need to remove the import statement from app-routing.module.ts

                                      – tyro
                                      Jul 5 '18 at 5:12














                                    87












                                    87








                                    87








                                    1. Delete the folder containing this component.

                                    2. In the app.module.ts remove the import statement for this component and remove its name from the declaration section of @NgModule

                                    3. Remove the line with the export statement for this component from index.ts.






                                    share|improve this answer














                                    1. Delete the folder containing this component.

                                    2. In the app.module.ts remove the import statement for this component and remove its name from the declaration section of @NgModule

                                    3. Remove the line with the export statement for this component from index.ts.







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Dec 28 '16 at 3:18









                                    Yakov FainYakov Fain

                                    7,23832027




                                    7,23832027








                                    • 8





                                      where is index.ts ? Thanks

                                      – Shane G
                                      May 10 '17 at 20:12






                                    • 31





                                      in the latest versions of CLI they don't generate it.

                                      – Yakov Fain
                                      May 11 '17 at 0:08






                                    • 3





                                      I think one more step is missing... run ng serve again, isn't it?

                                      – gsalgadotoledo
                                      Jul 22 '17 at 1:08











                                    • index.ts? Not in 5

                                      – Andrew Koper
                                      Mar 11 '18 at 23:22











                                    • in Angular6, need to remove the import statement from app-routing.module.ts

                                      – tyro
                                      Jul 5 '18 at 5:12














                                    • 8





                                      where is index.ts ? Thanks

                                      – Shane G
                                      May 10 '17 at 20:12






                                    • 31





                                      in the latest versions of CLI they don't generate it.

                                      – Yakov Fain
                                      May 11 '17 at 0:08






                                    • 3





                                      I think one more step is missing... run ng serve again, isn't it?

                                      – gsalgadotoledo
                                      Jul 22 '17 at 1:08











                                    • index.ts? Not in 5

                                      – Andrew Koper
                                      Mar 11 '18 at 23:22











                                    • in Angular6, need to remove the import statement from app-routing.module.ts

                                      – tyro
                                      Jul 5 '18 at 5:12








                                    8




                                    8





                                    where is index.ts ? Thanks

                                    – Shane G
                                    May 10 '17 at 20:12





                                    where is index.ts ? Thanks

                                    – Shane G
                                    May 10 '17 at 20:12




                                    31




                                    31





                                    in the latest versions of CLI they don't generate it.

                                    – Yakov Fain
                                    May 11 '17 at 0:08





                                    in the latest versions of CLI they don't generate it.

                                    – Yakov Fain
                                    May 11 '17 at 0:08




                                    3




                                    3





                                    I think one more step is missing... run ng serve again, isn't it?

                                    – gsalgadotoledo
                                    Jul 22 '17 at 1:08





                                    I think one more step is missing... run ng serve again, isn't it?

                                    – gsalgadotoledo
                                    Jul 22 '17 at 1:08













                                    index.ts? Not in 5

                                    – Andrew Koper
                                    Mar 11 '18 at 23:22





                                    index.ts? Not in 5

                                    – Andrew Koper
                                    Mar 11 '18 at 23:22













                                    in Angular6, need to remove the import statement from app-routing.module.ts

                                    – tyro
                                    Jul 5 '18 at 5:12





                                    in Angular6, need to remove the import statement from app-routing.module.ts

                                    – tyro
                                    Jul 5 '18 at 5:12











                                    21














                                    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.






                                    share|improve this answer






























                                      21














                                      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.






                                      share|improve this answer




























                                        21












                                        21








                                        21







                                        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.






                                        share|improve this answer















                                        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.







                                        share|improve this answer














                                        share|improve this answer



                                        share|improve this answer








                                        edited Sep 20 '17 at 9:06

























                                        answered Jun 16 '17 at 17:17









                                        UniCoderUniCoder

                                        1,1241316




                                        1,1241316























                                            8














                                            Currently Angular CLI doesn't support an option to remove the component, you need to do it manually.




                                            1. Remove import references for every component from app.module

                                            2. Delete component folders.






                                            share|improve this answer




























                                              8














                                              Currently Angular CLI doesn't support an option to remove the component, you need to do it manually.




                                              1. Remove import references for every component from app.module

                                              2. Delete component folders.






                                              share|improve this answer


























                                                8












                                                8








                                                8







                                                Currently Angular CLI doesn't support an option to remove the component, you need to do it manually.




                                                1. Remove import references for every component from app.module

                                                2. Delete component folders.






                                                share|improve this answer













                                                Currently Angular CLI doesn't support an option to remove the component, you need to do it manually.




                                                1. Remove import references for every component from app.module

                                                2. Delete component folders.







                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered Apr 2 '17 at 23:54









                                                Bernardo SorianoBernardo Soriano

                                                8112




                                                8112























                                                    4














                                                    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.






                                                    share|improve this answer




























                                                      4














                                                      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.






                                                      share|improve this answer


























                                                        4












                                                        4








                                                        4







                                                        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.






                                                        share|improve this answer













                                                        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.







                                                        share|improve this answer












                                                        share|improve this answer



                                                        share|improve this answer










                                                        answered Apr 25 '18 at 21:17









                                                        babidibabidi

                                                        25633




                                                        25633























                                                            4














                                                            I wrote a bash script that should automate the process written by Yakov Fain below. It can be called like ./removeComponent myComponentName This has only been tested with Angular 6



                                                            #!/bin/bash
                                                            if [ "$#" -ne 1 ]; then
                                                            echo "Input a component to delete"
                                                            exit 1
                                                            fi

                                                            # finds folder with component name and deletes
                                                            find . -type d -name $1 | xargs rm -rf

                                                            # removes lines referencing the component from app.module.ts
                                                            grep -v $1 app.module.ts > temp
                                                            mv temp app.module.ts

                                                            componentName=$1
                                                            componentName+="Component"

                                                            grep -v -i $componentName app.module.ts > temp
                                                            mv temp app.module.ts





                                                            share|improve this answer


























                                                            • Please add a note for me to change this if the angular cli changes in the future

                                                              – Aidan Grimshaw
                                                              Oct 8 '18 at 6:30
















                                                            4














                                                            I wrote a bash script that should automate the process written by Yakov Fain below. It can be called like ./removeComponent myComponentName This has only been tested with Angular 6



                                                            #!/bin/bash
                                                            if [ "$#" -ne 1 ]; then
                                                            echo "Input a component to delete"
                                                            exit 1
                                                            fi

                                                            # finds folder with component name and deletes
                                                            find . -type d -name $1 | xargs rm -rf

                                                            # removes lines referencing the component from app.module.ts
                                                            grep -v $1 app.module.ts > temp
                                                            mv temp app.module.ts

                                                            componentName=$1
                                                            componentName+="Component"

                                                            grep -v -i $componentName app.module.ts > temp
                                                            mv temp app.module.ts





                                                            share|improve this answer


























                                                            • Please add a note for me to change this if the angular cli changes in the future

                                                              – Aidan Grimshaw
                                                              Oct 8 '18 at 6:30














                                                            4












                                                            4








                                                            4







                                                            I wrote a bash script that should automate the process written by Yakov Fain below. It can be called like ./removeComponent myComponentName This has only been tested with Angular 6



                                                            #!/bin/bash
                                                            if [ "$#" -ne 1 ]; then
                                                            echo "Input a component to delete"
                                                            exit 1
                                                            fi

                                                            # finds folder with component name and deletes
                                                            find . -type d -name $1 | xargs rm -rf

                                                            # removes lines referencing the component from app.module.ts
                                                            grep -v $1 app.module.ts > temp
                                                            mv temp app.module.ts

                                                            componentName=$1
                                                            componentName+="Component"

                                                            grep -v -i $componentName app.module.ts > temp
                                                            mv temp app.module.ts





                                                            share|improve this answer















                                                            I wrote a bash script that should automate the process written by Yakov Fain below. It can be called like ./removeComponent myComponentName This has only been tested with Angular 6



                                                            #!/bin/bash
                                                            if [ "$#" -ne 1 ]; then
                                                            echo "Input a component to delete"
                                                            exit 1
                                                            fi

                                                            # finds folder with component name and deletes
                                                            find . -type d -name $1 | xargs rm -rf

                                                            # removes lines referencing the component from app.module.ts
                                                            grep -v $1 app.module.ts > temp
                                                            mv temp app.module.ts

                                                            componentName=$1
                                                            componentName+="Component"

                                                            grep -v -i $componentName app.module.ts > temp
                                                            mv temp app.module.ts






                                                            share|improve this answer














                                                            share|improve this answer



                                                            share|improve this answer








                                                            edited Nov 21 '18 at 3:10

























                                                            answered Jun 22 '18 at 23:30









                                                            Aidan GrimshawAidan Grimshaw

                                                            4113




                                                            4113













                                                            • Please add a note for me to change this if the angular cli changes in the future

                                                              – Aidan Grimshaw
                                                              Oct 8 '18 at 6:30



















                                                            • Please add a note for me to change this if the angular cli changes in the future

                                                              – Aidan Grimshaw
                                                              Oct 8 '18 at 6:30

















                                                            Please add a note for me to change this if the angular cli changes in the future

                                                            – Aidan Grimshaw
                                                            Oct 8 '18 at 6:30





                                                            Please add a note for me to change this if the angular cli changes in the future

                                                            – Aidan Grimshaw
                                                            Oct 8 '18 at 6:30











                                                            2














                                                            I am not sure if it is the best way, but it worked for me.




                                                            • First, I deleted the component folder.

                                                            • Then, I cleared app.module.ts, app.component.ts & app.component.html of the imports and declarations related to the component I wanted to delete.

                                                            • Similarly, I cleared main.ts.


                                                            I just saved and refreshed the app and it worked.






                                                            share|improve this answer




























                                                              2














                                                              I am not sure if it is the best way, but it worked for me.




                                                              • First, I deleted the component folder.

                                                              • Then, I cleared app.module.ts, app.component.ts & app.component.html of the imports and declarations related to the component I wanted to delete.

                                                              • Similarly, I cleared main.ts.


                                                              I just saved and refreshed the app and it worked.






                                                              share|improve this answer


























                                                                2












                                                                2








                                                                2







                                                                I am not sure if it is the best way, but it worked for me.




                                                                • First, I deleted the component folder.

                                                                • Then, I cleared app.module.ts, app.component.ts & app.component.html of the imports and declarations related to the component I wanted to delete.

                                                                • Similarly, I cleared main.ts.


                                                                I just saved and refreshed the app and it worked.






                                                                share|improve this answer













                                                                I am not sure if it is the best way, but it worked for me.




                                                                • First, I deleted the component folder.

                                                                • Then, I cleared app.module.ts, app.component.ts & app.component.html of the imports and declarations related to the component I wanted to delete.

                                                                • Similarly, I cleared main.ts.


                                                                I just saved and refreshed the app and it worked.







                                                                share|improve this answer












                                                                share|improve this answer



                                                                share|improve this answer










                                                                answered Aug 10 '17 at 16:29









                                                                TheMeanCoderTheMeanCoder

                                                                211




                                                                211























                                                                    1














                                                                    From app.module.ts:




                                                                    • erase import line for the specific component;

                                                                    • erase its declaration from @NgModule;


                                                                    Then delete the folder of the component you want to delete and its included files (.component.ts, .component.html, .component.css and .component.spec.ts).



                                                                    Done.



                                                                    -



                                                                    I read people saying about erasing it from main.ts. You were not supposed to import it from there in the first place as it already imports AppModule, and AppModule is the one importing all the components you created.






                                                                    share|improve this answer






























                                                                      1














                                                                      From app.module.ts:




                                                                      • erase import line for the specific component;

                                                                      • erase its declaration from @NgModule;


                                                                      Then delete the folder of the component you want to delete and its included files (.component.ts, .component.html, .component.css and .component.spec.ts).



                                                                      Done.



                                                                      -



                                                                      I read people saying about erasing it from main.ts. You were not supposed to import it from there in the first place as it already imports AppModule, and AppModule is the one importing all the components you created.






                                                                      share|improve this answer




























                                                                        1












                                                                        1








                                                                        1







                                                                        From app.module.ts:




                                                                        • erase import line for the specific component;

                                                                        • erase its declaration from @NgModule;


                                                                        Then delete the folder of the component you want to delete and its included files (.component.ts, .component.html, .component.css and .component.spec.ts).



                                                                        Done.



                                                                        -



                                                                        I read people saying about erasing it from main.ts. You were not supposed to import it from there in the first place as it already imports AppModule, and AppModule is the one importing all the components you created.






                                                                        share|improve this answer















                                                                        From app.module.ts:




                                                                        • erase import line for the specific component;

                                                                        • erase its declaration from @NgModule;


                                                                        Then delete the folder of the component you want to delete and its included files (.component.ts, .component.html, .component.css and .component.spec.ts).



                                                                        Done.



                                                                        -



                                                                        I read people saying about erasing it from main.ts. You were not supposed to import it from there in the first place as it already imports AppModule, and AppModule is the one importing all the components you created.







                                                                        share|improve this answer














                                                                        share|improve this answer



                                                                        share|improve this answer








                                                                        edited Nov 13 '17 at 3:48









                                                                        Mike Stockdale

                                                                        4,68832533




                                                                        4,68832533










                                                                        answered Nov 13 '17 at 2:15









                                                                        cheddarcheddar

                                                                        111




                                                                        111























                                                                            -1














                                                                            First of all, remove component folder, which you have to delete
                                                                            and then remove its entries which you have made in "ts" files.






                                                                            share|improve this answer






























                                                                              -1














                                                                              First of all, remove component folder, which you have to delete
                                                                              and then remove its entries which you have made in "ts" files.






                                                                              share|improve this answer




























                                                                                -1












                                                                                -1








                                                                                -1







                                                                                First of all, remove component folder, which you have to delete
                                                                                and then remove its entries which you have made in "ts" files.






                                                                                share|improve this answer















                                                                                First of all, remove component folder, which you have to delete
                                                                                and then remove its entries which you have made in "ts" files.







                                                                                share|improve this answer














                                                                                share|improve this answer



                                                                                share|improve this answer








                                                                                edited Dec 8 '17 at 6:00









                                                                                clemens

                                                                                10.3k102541




                                                                                10.3k102541










                                                                                answered Dec 8 '17 at 5:50









                                                                                the shashankthe shashank

                                                                                11




                                                                                11























                                                                                    -1














                                                                                    If you looking for some command in CLI, Then ans is NO for now.
                                                                                    But you can do manually by deleting the component folder and all the references.






                                                                                    share|improve this answer




























                                                                                      -1














                                                                                      If you looking for some command in CLI, Then ans is NO for now.
                                                                                      But you can do manually by deleting the component folder and all the references.






                                                                                      share|improve this answer


























                                                                                        -1












                                                                                        -1








                                                                                        -1







                                                                                        If you looking for some command in CLI, Then ans is NO for now.
                                                                                        But you can do manually by deleting the component folder and all the references.






                                                                                        share|improve this answer













                                                                                        If you looking for some command in CLI, Then ans is NO for now.
                                                                                        But you can do manually by deleting the component folder and all the references.







                                                                                        share|improve this answer












                                                                                        share|improve this answer



                                                                                        share|improve this answer










                                                                                        answered Dec 28 '17 at 8:22









                                                                                        Hidayt RahmanHidayt Rahman

                                                                                        1,0451220




                                                                                        1,0451220























                                                                                            -1














                                                                                            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.






                                                                                            share|improve this answer






























                                                                                              -1














                                                                                              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.






                                                                                              share|improve this answer




























                                                                                                -1












                                                                                                -1








                                                                                                -1







                                                                                                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.






                                                                                                share|improve this answer















                                                                                                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.







                                                                                                share|improve this answer














                                                                                                share|improve this answer



                                                                                                share|improve this answer








                                                                                                edited Jan 14 at 9:45

























                                                                                                answered Dec 21 '18 at 7:27









                                                                                                DevaDeva

                                                                                                696




                                                                                                696

















                                                                                                    protected by eyllanesc Jun 23 '18 at 0:17



                                                                                                    Thank you for your interest in this question.
                                                                                                    Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



                                                                                                    Would you like to answer one of these unanswered questions instead?



                                                                                                    Popular posts from this blog

                                                                                                    "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

                                                                                                    Alcedinidae

                                                                                                    RAC Tourist Trophy