How to generate Angular components in a specific folder?
Guest post by Ahmed Bouchefra, check out the Angular newsletter for more tips.
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
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
component directly inside the