Angular cli commands list

Angular cli commands list

In this tutorial, we will learn about some basic commands which are commonly used in Angular cli.

ng new

This command is used to create a new angular project.

ng new myapp

ng generate

This command is used to generate new components, routing modules, services, and guards.

Create new components

ng generate component myfirst-component

#where myfirst-component is your component name

This above command can also be written as

ng g c myfirst-component

# g means generate
# c means component

Create new services

ng g s  my-service

#s means service

This above command will create new services in your app, by default services are injected into root level.

Create route guards

ng generate guard auth-guard

#where auth-guard is your guard name

Once you run this above command you will see three available guards and you need to choose which guard is required for you.

? Which interfaces would you like to implement?
(Press <space> to select, <a> to toggle all, <i> to invert selection)
❯◯ CanActivate
 ◯ CanActivateChild
 ◯ CanLoad

Create custom directives

ng generate directive emoji

This command will create a new custom directive called emoji in your app folder.

ng serve

This command is used to start the local development server so that you can develop your favorite app on your pc.

ng serve

ng test

This command is used to run the unit tests in a project.

ng test

ng e2e

This command is used to run the end to end tests in a project.

ng e2e

ng build

This command is used to build your app for production use.

ng build