Angular CLI
Angular CLI (ng) is a command-line interface for Angular. It allows you to create, build, test, and run Angular applications from the command line. Let’s dive into the essential aspects of Angular CLI for programmers.
Installing
Section titled “Installing”To install the Angular CLI, run the following command:
npm install -g @angular/cliCreating a New Project
Section titled “Creating a New Project”To create a new Angular project, run the following command:
ng new my-appThis will create a new Angular project named my-app in the current directory. You can also specify the directory name as follows:
ng new my-app --directory my-dirGenerating Components
Section titled “Generating Components”To generate a new component, run the following command:
ng generate component my-componentThis will create a new component named my-component in the src/app directory. You can also specify the directory name as follows:
ng generate component my-component --directory my-dirUpdating Angular
Section titled “Updating Angular”To update Angular in an existing project, run the following command:
ng update @angular/cli @angular/coreUpdating Angular CLI
Section titled “Updating Angular CLI”To update the Angular CLI, run the following command:
npm install -g @angular/cli@latestRunning the Application
Section titled “Running the Application”To run the application, run the following command:
ng serveThis will start the application on port 4200. You can also specify the port number as follows:
ng serve --port 3000Building the Application
Section titled “Building the Application”To build the application, run the following command:
ng buildTesting the Application
Section titled “Testing the Application”To test the application, run the following command:
ng testThis will run all the tests in the src/app directory.
Debugging the Application
Section titled “Debugging the Application”To debug the application, run the following command:
ng serve --inspectThis will start the application in debug mode. You can then attach a debugger to the application.