How to generate Angular components in a specific folder?

More often than not, we need to generate our Angular components inside specific folders for the sake of better structuring our application.

This is how I use Angular CLI to generate a component inside a specific folder.

We can simply use the ng g c command followed by the folder path as follows:

ng g c buttons/home

This command will generate a home component inside the app/buttons/home folder.

Please note that if the buttons folder doesn’t exist Angular CLI will automatically create it.

If you don’t want to have the home subfolder created, you simply need to add the --flat option to the command as follows:

ng g c buttons/home --flat

This command will generate the files of the home component directly inside the app/components/ folder.

This is all for this thread, if you have other tips related to this topic please share them below!

Published at WebTutPro.