What is the best way to delete a component with CLI
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
add a comment |
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
add a comment |
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
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
angular angular-cli
asked Dec 28 '16 at 2:54
Jus10Jus10
1,63221244
1,63221244
add a comment |
add a comment |
11 Answers
11
active
oldest
votes
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.
add a comment |
- Delete the folder containing this component.
- In the app.module.ts remove the import statement for this component and remove its name from the declaration section of @NgModule
- Remove the line with the export statement for this component from index.ts.
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
add a comment |
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
).
- It creates a separate folder named
demoComponent
(ng g c demoComponent
). - It generate
HTML,CSS,ts
and aspec
file dedicated to demoComponent. - Also, It adds dependency inside app.module.ts file to add that component to your project.
so do it in reverse order
- Remove Dependency from
app.module.ts
- Delete that component folder.
add a comment |
Currently Angular CLI doesn't support an option to remove the component, you need to do it manually.
- Remove import references for every component from app.module
- Delete component folders.
add a comment |
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.
add a comment |
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
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
add a comment |
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.
add a comment |
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.
add a comment |
First of all, remove component folder, which you have to delete
and then remove its entries which you have made in "ts" files.
add a comment |
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.
add a comment |
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.
add a comment |
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
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.
add a comment |
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.
add a comment |
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.
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.
edited Jan 12 at 20:35
Liam
16.2k1676129
16.2k1676129
answered Dec 28 '16 at 3:13
BroccoBrocco
39.6k85271
39.6k85271
add a comment |
add a comment |
- Delete the folder containing this component.
- In the app.module.ts remove the import statement for this component and remove its name from the declaration section of @NgModule
- Remove the line with the export statement for this component from index.ts.
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
add a comment |
- Delete the folder containing this component.
- In the app.module.ts remove the import statement for this component and remove its name from the declaration section of @NgModule
- Remove the line with the export statement for this component from index.ts.
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
add a comment |
- Delete the folder containing this component.
- In the app.module.ts remove the import statement for this component and remove its name from the declaration section of @NgModule
- Remove the line with the export statement for this component from index.ts.
- Delete the folder containing this component.
- In the app.module.ts remove the import statement for this component and remove its name from the declaration section of @NgModule
- Remove the line with the export statement for this component from index.ts.
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
add a comment |
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
add a comment |
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
).
- It creates a separate folder named
demoComponent
(ng g c demoComponent
). - It generate
HTML,CSS,ts
and aspec
file dedicated to demoComponent. - Also, It adds dependency inside app.module.ts file to add that component to your project.
so do it in reverse order
- Remove Dependency from
app.module.ts
- Delete that component folder.
add a comment |
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
).
- It creates a separate folder named
demoComponent
(ng g c demoComponent
). - It generate
HTML,CSS,ts
and aspec
file dedicated to demoComponent. - Also, It adds dependency inside app.module.ts file to add that component to your project.
so do it in reverse order
- Remove Dependency from
app.module.ts
- Delete that component folder.
add a comment |
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
).
- It creates a separate folder named
demoComponent
(ng g c demoComponent
). - It generate
HTML,CSS,ts
and aspec
file dedicated to demoComponent. - Also, It adds dependency inside app.module.ts file to add that component to your project.
so do it in reverse order
- Remove Dependency from
app.module.ts
- Delete that component folder.
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
).
- It creates a separate folder named
demoComponent
(ng g c demoComponent
). - It generate
HTML,CSS,ts
and aspec
file dedicated to demoComponent. - Also, It adds dependency inside app.module.ts file to add that component to your project.
so do it in reverse order
- Remove Dependency from
app.module.ts
- Delete that component folder.
edited Sep 20 '17 at 9:06
answered Jun 16 '17 at 17:17
UniCoderUniCoder
1,1241316
1,1241316
add a comment |
add a comment |
Currently Angular CLI doesn't support an option to remove the component, you need to do it manually.
- Remove import references for every component from app.module
- Delete component folders.
add a comment |
Currently Angular CLI doesn't support an option to remove the component, you need to do it manually.
- Remove import references for every component from app.module
- Delete component folders.
add a comment |
Currently Angular CLI doesn't support an option to remove the component, you need to do it manually.
- Remove import references for every component from app.module
- Delete component folders.
Currently Angular CLI doesn't support an option to remove the component, you need to do it manually.
- Remove import references for every component from app.module
- Delete component folders.
answered Apr 2 '17 at 23:54
Bernardo SorianoBernardo Soriano
8112
8112
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Apr 25 '18 at 21:17
babidibabidi
25633
25633
add a comment |
add a comment |
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Aug 10 '17 at 16:29
TheMeanCoderTheMeanCoder
211
211
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
edited Nov 13 '17 at 3:48
Mike Stockdale
4,68832533
4,68832533
answered Nov 13 '17 at 2:15
cheddarcheddar
111
111
add a comment |
add a comment |
First of all, remove component folder, which you have to delete
and then remove its entries which you have made in "ts" files.
add a comment |
First of all, remove component folder, which you have to delete
and then remove its entries which you have made in "ts" files.
add a comment |
First of all, remove component folder, which you have to delete
and then remove its entries which you have made in "ts" files.
First of all, remove component folder, which you have to delete
and then remove its entries which you have made in "ts" files.
edited Dec 8 '17 at 6:00
clemens
10.3k102541
10.3k102541
answered Dec 8 '17 at 5:50
the shashankthe shashank
11
11
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Dec 28 '17 at 8:22
Hidayt RahmanHidayt Rahman
1,0451220
1,0451220
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
edited Jan 14 at 9:45
answered Dec 21 '18 at 7:27
DevaDeva
696
696
add a comment |
add a comment |
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?