Tutorial

Cheatsheet: Angular CLI Reference

Updated on October 28, 2020
authorauthor

Alligator.io and Matt Abrams

Cheatsheet: Angular CLI Reference

Introduction

Here’s a cheat sheet that will help you find the commands you need for most of the things that you would want to do with the Angular CLI. For a brief introduction to the Angular CLI you can explore this tutorial.

Checking the Version

See which version of the CLI you’re using:

  1. ng --version

Updating the Version

Run this:

  1. npm uninstall -g @angular/cli cache clean
  2. npm install -g @angular/cli@latest

Help

Get general help:

  1. ng help

Or get help for a specific command:

  1. ng help generate

New Project

Generate a new project:

  1. ng new my-app

And here are a few flags you can use:

  • --dry-run: See which files would be created, but don’t actually do anything.
  • --verbose: Be more chatty.
  • --skip-install: Don’t npm install, useful when offline or with slow internet.
  • --skip-tests: Don’t create spec files.
  • --skip-git: Don’t initialize a git repo.
  • --source-dir: Name of the source directory
  • --routing: Add routing to the app.
  • --prefix: Specify the prefix to use for components selectors.
  • --style: Defaults to css, but can be set to scss.
  • --inline-style: Use inline styles for components instead of separate files.
  • --inline-template: Use inline templates for components instead of separate files.

Here’s an example with a few flags:

  1. ng new my-app --prefix yo --style scss --skip-tests --verbose

Generate All The Things

Generate a component:

  1. ng g c unicorn-component

Generate a service:

  1. ng g s everything-service

Generate a pipe:

  1. ng g pipe my-pipe

Generate a directive:

  1. ng g directive my-directive

Generate an enum:

  1. ng g enum some-enum

Generate a module:

  1. ng g module fancy-module

Generate a class:

  1. ng g cl my-class

Generate an interface:

  1. ng g interface my-interface

Generate a route guard:

  1. ng g guard my-guard

The --dry-run and --verbose flags can be used with any generate command.

Serving

Serve your project

  1. ng s

Serve and open in your default browser automatically:

  1. ng s -o

Serve to a different port:

  1. ng s --port 5555

Running Your Tests

  1. ng test

And some flags you can use with the test command:

  • --watch: Retest when some files change.
  • --code-coverage: Add a coverage report.
  • --progress: Show the progress while running the tests.
  • --browsers: Specify which browsers to use.
  • --colors: Use colors in the output or not.

Linting

Run the linter:

  1. ng lint

A few flags for the linter:

  • --fix: Apply fixes for linting errors.
  • --force: Force success even when linting fails.

Building Your App

Build your app with the build command:

  1. ng build

And here are some flags that you can use with build:

  • --target: Specify the target for the build (e.g.: --target production).
  • --aot: Use ahead of time compilation.
  • --base-href: Specify the base href to use.
  • --deploy-url: Specify the deployment url.
  • --extract-css: Put the global styles in a CSS file instead of keeping it in the JavaScript.
  • --watch: Rebuild every time a file changes.

Ejecting Your Webpack Config

The Angular CLI doesn’t do it for your project anymore? Just eject, and you’ll have the full Webpack config available to tweak to your heart’s desire:

  1. ng eject

Conclusion

These are some of the most common commands for the Angular CLI. For a brief introduction to the Angular CLI, you can explore this tutorial.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors
Default avatar
Alligator.io

author



Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
1 Comments


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Thank you

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.