How would you generate a new component, service, or module using Angular CLI commands?
Short answer
The CLI provides generate commands, often shortened to g, that create new files following Angular's recommended structure and naming conventions automatically, saving you from manually creating and wiring up each file by hand.
Advertisement
AModel answer
The CLI provides generate commands, often shortened to g, that create new files following Angular's recommended structure and naming conventions automatically, saving you from manually creating and wiring up each file by hand.
ng generate component user-profile
// shorthand version
ng g c user-profile
ng generate service auth
ng g s authReal-world example
A developer adding a new feature generates a component and its matching service using two quick CLI commands, instantly getting properly named and structured files instead of manually creating them from scratch.
Likely follow-ups
- What files does generating a new component actually create?
- How would you generate a component without an accompanying test file?
Related topics