Angular All Commands

Here is a list of the most commonly used Angular CLI commands:

Global Angular CLI Commands

  1. Install Angular CLI
    Installs the Angular CLI globally:

    bash
    npm install -g @angular/cli
  2. Check Angular CLI Version
    Displays the version of the installed Angular CLI:

    bash
    ng version
  3. Help Command
    Displays help for available commands:

    bash
    ng help

Project Management Commands

  1. Create a New Angular Project
    Creates a new Angular project:

    bash
    ng new project-name
  2. Run Development Server
    Runs the app locally with live reload:

    bash
    ng serve
  3. Build Project for Production
    Builds the project for production:

    bash
    ng build --prod
  4. Run Unit Tests
    Runs unit tests with Karma:

    bash
    ng test
  5. Run End-to-End Tests
    Runs end-to-end tests using Protractor:

    bash
    ng e2e

Updating and Maintenance Commands

  1. Update Angular Dependencies
    Updates Angular to a newer version:

    bash
    ng update @angular/core @angular/cli
  2. Add New Dependencies or Features
    Adds a new package or Angular features (e.g., PWA, Material):

    bash
    ng add package-name
  3. Linting Project
    Lints the project and checks for coding standards:

    bash
    ng lint
  4. Run Code Formatting (Prettier)
    If you have Prettier installed, format the project files:

    bash
    npx prettier --write .

Generating Code

  1. Generate a Component
    Creates a new Angular component:

    bash
    <
    ng generate component component-name # or shorthand: ng g c component-name
  2. Generate a Service
    Creates a new Angular service:

    bash
    ng generate service service-name # or shorthand: ng g s service-name
  3. Generate a Module
    Creates a new Angular module:

    bash
    ng generate module module-name # or shorthand: ng g m module-name
  4. Generate a Directive
    Creates a new Angular directive:

    bash
    ng generate directive directive-name # or shorthand: ng g d directive-name
  5. Generate a Pipe
    Creates a new Angular pipe:

    bash
    ng generate pipe pipe-name # or shorthand: ng g p pipe-name
  6. Generate a Guard
    Creates a new Angular guard:

    bash
    ng generate guard guard-name # or shorthand: ng g g guard-name
  7. Generate a Class/Interface/Enum
    Generates classes, interfaces, and enums:

    bash
    ng generate class class-name ng generate interface interface-name ng generate enum enum-name

Miscellaneous Commands

  1. Run a Custom Script
    Runs a custom npm script from the package.json:

    bash
    npm run script-name
  2. Run Server with a Specific Port
    Runs the development server on a custom port:

    bash
    ng serve --port 4201
  3. Open Project in Default Browser
    Opens the app in the default browser while serving:

    bash
    ng serve --open
  4. Analyze Build Size
    Generates a production build and analyzes the bundle size:

    bash
    ng build --prod --stats-json npx webpack-bundle-analyzer dist/project-name/stats.json

Deployment Commands

  1. Deploy to GitHub Pages
    Deploys the project to GitHub Pages (after adding angular-cli-ghpages):
    bash
    ng add angular-cli-ghpages ng deploy

These commands cover most tasks you’ll perform while developing Angular applications.

Post a Comment

0 Comments