Back to results for “Project Structure”
Angular › Angular CLI & Project Structure

How would you generate a new component, service, or module using Angular CLI commands?

Intermediate

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 auth
Real-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.

Common follow-ups: What files does generating a new component actually create?;How would you generate a component without an accompanying test file?