Generate Angular components in specific folders with Angular CLI

WebTutPro
webtutpro
Published in
1 min readApr 26, 2021

--

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/buttons/ folder.

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

--

--