Introduction
Angular CLI is a powerful command-line tool that facilitates the development of Angular applications. It streamlines the process of creating, building, testing, and deploying Angular projects. This documentation provides an overview of Angular CLI, its installation, basic commands, and a coding example to demonstrate its usage.
Installation
To use Angular CLI, you need to have Node.js installed on your system. Once Node.js is installed, open your terminal or command prompt and run the following command to install Angular CLI globally:
bashnpm install -g @angular/cli
Basic Commands
Angular CLI provides various commands to perform common tasks during the development process:
ng new [project-name]:
Creates a new Angular project with the specified name.ng serve:
Builds and serves the application in development mode. The app will be accessible athttp://localhost:4200/
.ng generate [schematic]:
Generates different elements of the application, such as components, services, modules, etc.ng build:
Builds the application for production deployment.ng test:
Executes unit tests using Karma.ng e2e:
Runs end-to-end tests using Protractor.
Example: Creating a New Component
Let's create a simple component using Angular CLI:
- First, create a new Angular project using the following command:
bashng new my-app
- Change into the project directory:
bashcd my-app
- Now, generate a new component named 'example':
bashng generate component example
- This will create the 'example' component with its files and folder structure.
Explanation
ng new
command sets up a new Angular project in the 'my-app' directory.ng generate component
orng g c
is used to create the 'example' component, automatically generating its files like HTML, CSS, TypeScript, and spec files.
Now, you have a basic understanding of Angular CLI and its usage to create a new Angular component.
Please note that this is a brief overview, and Angular CLI offers many more features and commands to enhance the development workflow of Angular applications. For more detailed information, consult the official Angular CLI documentation: https://angular.io/cli
0 Comments