DEV Community

Angular CLI shortcuts for generating components

Sometimes when we need to create a new element, we copy a component and paste renaming the files instead of using the proper command of angular CLI.

I think is important to follow the right approach and use the angular CLI commands because in this way, take it for sure
that you will speed up your times.

For that, I will share with you, what I use the most.

element command short way
Component ng g component nameComponent ng g c nameComponent
Service ng g service nameService ng g s nameService
Enum ng g enum nameEnum ng g e nameEnum
Interface ng g interface nameInterface ng g i
Module ng g module nameModule ng g m nameModule
Guard ng g guard nameGuard ng g g
Pipe ng g pipe namePipe ng g p

Also, we can indicate some options:

--flat -> with this we can generate the element without create a new directory.
--inline-style or -is -> avoid generate the css file
--inline-template or -it -> avoid generate html file
--skip-tests -> avoid generate spec file

Discussion (1)

anduser96 profile image
Andrei Gatej

Thanks for sharing.

There is also one that I found really useful, at least when generating components, and that is the -d(dry run) flag.