Steps to remove undesired component from the App In this example we will go to the path fullApp\Ionic5FullApp\src\app\pages\layouts and delete the corresponding folder 'uber-map-flow'. Similarly you have to search for the folder of the page that you want to remove and then just simply go and delete it.
Select a component you want to delete 2. Go to Plugins > Safely Delete Components > Safe Delete (or ⌘+/ > "Safe Delete") 3. This component will be deleted if there are no instances of it in the document 🧹 Delete Unused Components 1.
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.
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.
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
).
demoComponent
(ng g c demoComponent
).HTML,CSS,ts
and a spec
file dedicated to demoComponent.so do it in reverse order
app.module.ts
when removing the dependency you have to do two things.
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.
Currently Angular CLI doesn't support an option to remove the component, you need to do it manually.
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 am not sure if it is the best way, but it worked for me.
I just saved and refreshed the app and it worked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With