Angular CLI
Angular CLI
Section titled βAngular CLIβWhat it means
Section titled βWhat it meansβThe Angular CLI (ng) is the official command-line tool for creating, developing, testing, and building Angular projects. It scaffolds new projects and components with consistent structure, wires up build tooling (via esbuild/Vite in modern Angular versions), and wraps common workflows β dev server, testing, linting β behind simple commands.
Examples
Section titled βExamplesβnpm install -g @angular/cli # install the CLI globally
ng new my-app # scaffold a new project (prompts for options)cd my-appng serve # start the dev server at localhost:4200 with live reload
ng generate component user-profile # or shorthand: ng g c user-profileng generate service auth # or: ng g s auth
ng build # production build, output to dist/ng test # run unit testsng lint # run the linterCommon mistake
Section titled βCommon mistakeβManually creating component files by hand-copying an existing one β this is error-prone (mismatched selectors, stale imports, forgotten registration) compared to ng generate component, which creates all the right files with correct naming and wiring in one step.
# Error-prone: copy-paste an existing component and edit by handcp -r src/app/user-profile src/app/user-settings# now manually fix: class name, selector, template filename references, tests...
# Reliable: let the CLI generate it correctly the first timeng generate component user-settingsQuick practice
Section titled βQuick practiceβ-
What command creates a brand-new Angular project?
Answer
ng new my-app -
Whatβs the shorthand for
ng generate component?Answer
ng g cβ e.g.ng g c user-profile. -
Why is
ng generategenerally preferred over manually copying an existing componentβs files?Answer
It reliably produces correctly-named, correctly-wired files (class name, selector, imports, test scaffold) in one step, avoiding the small mismatches that creep in from manual copy-paste.