Angular 22 cheatsheet

Angular 22: Angular CLI

12 common Angular 22 tasks.

Install the Angular CLI

Install the command-line tool globally.

npm install -g @angular/cli

Create an app

Create a new workspace with an application.

ng new my-app

Start the dev server

Build and serve the app with live reload at http://localhost:4200.

ng serve

Serve and open the browser

Start the dev server on a given port and open the browser.

ng serve --port 4300 --open

Generate a component

Create a component with its template, styles and test.

ng generate component users/user-card

Generate a service

Create an injectable service.

ng generate service services/auth

Preview what a generator creates

List the files without writing anything.

ng generate component users/user-card --dry-run

Generate other building blocks

Generate a route guard, pipe, directive or interface.

ng generate guard auth
ng generate pipe truncate
ng generate directive highlight
ng generate interface user

Build for production

Create an optimized build in dist.

ng build

Run unit tests

Run the unit tests with the configured test runner.

ng test

Add a library

Install a package and run its setup, for example Angular Material.

ng add @angular/material

Update Angular

List available updates, then update the core packages.

ng update
ng update @angular/core @angular/cli

Was this page helpful?