Skip to main content

Angular CLI

Angular projects are typically developed and managed using the Angular CLI (Command Line Interface). The Angular CLI provides a set of commands that help you create, build, test, and deploy your Angular applications. Here are some of the main commands that are commonly used in Angular development:

  1. Create a New Project:

    ng new project-name

    Creates a new Angular project with the specified name.

  2. Generate a Component:

    ng generate component component-name

    Generates a new Angular component.

  3. Generate a Service:

    ng generate service service-name

    Generates a new Angular service.

  4. Generate a Module:

    ng generate module module-name

    Generates a new Angular module.

  5. Build the Application:

    ng build

    Builds the Angular application for production. Use --prod flag for optimized production build.

  6. Serve the Application:

    ng serve

    Starts a development server and serves your application. By default, the app will be available at http://localhost:4200/.

  7. Run Tests:

    ng test

    Runs unit tests using Karma.

  8. Run End-to-End Tests:

    ng e2e

    Runs end-to-end tests using Protractor.

  9. Generate Component/Service/Module/Class...:

    ng generate <schematic> <name>

    Generates various elements like components, services, modules, classes, directives, etc.

  10. Lint the Code:

    ng lint

    Checks the code for linting issues using TSLint or ESLint.

  11. Update Dependencies:

    ng update

    Updates the project's dependencies based on the package.json file.

  12. Generate Documentation:

    ng doc <keyword>

    Opens Angular documentation in a browser based on a keyword.

These are just a few of the most commonly used Angular CLI commands. The Angular CLI provides a comprehensive set of commands to streamline the development process and maintain best practices. You can get more information about each command and its options by running ng help or by visiting the official Angular CLI documentation.