description |
---|
Missing command line interface documentation for Angular |
The official documentation for the Angular CLI is located in this repo's wiki.
Angular CLI is a command-line interface (CLI) to automate your development workflow. It allows you to:
- create a new Angular application
- run a development server with LiveReload support to preview your application during development
- add features to your existing Angular application
- run your application’s unit tests
- run your application’s end-to-end (E2E) tests
- build your application for deployment to production.
Both the CLI and generated project have dependencies that require Node 8.9
or higher, together with NPM 5.5.1
or higher.
You can download the latest version of Node.js for your operating system and consult the latest installation instructions on the official Node.js website.
If you already have Node.js and npm installed, you can verify their version by running:
{% code-tabs %} {% code-tabs-item title="displays your Node.js version" %}
node -v
{% endcode-tabs-item %} {% endcode-tabs %}
{% code-tabs %} {% code-tabs-item title="displays your npm version" %}
npm -v
{% endcode-tabs-item %} {% endcode-tabs %}
To install the Angular CLI:
npm install -g @angular/cli@latest
or
yarn global add @angular/cli@latest
Then make sure that it’s installed on your system and prints out version 6.0 or greater.
ng --version
ng help
Generating and serving an Angular project via a development server.
Create and run a new project:
ng new my-project
cd my-project
ng serve
Navigate to http://localhost:4200/. The app will automatically reload if you change any of the source files.
You can configure the default HTTP host and port used by the development server with two command-line options :
ng serve --host 0.0.0.0 --port 4201
You can use the ng generate
(or just ng g
) command to generate Angular components, directives, pipes, services and more.
You can find all possible blueprints in the table below:
Scaffold | Usage |
---|---|
Component | ng g component my-new-component |
Directive | ng g directive my-new-directive |
Pipe | ng g pipe my-new-pipe |
Service | ng g service my-new-service |
Class | ng g class my-new-class |
Guard | ng g guard my-new-guard |
Interface | ng g interface my-new-interface |
Enum | ng g enum my-new-enum |
Module | ng g module my-module |
angular-cli will add reference to components
, directives
and pipes
automatically in the app.module.ts
. If you need to add this references to another custom module, follow these steps:
ng g module new-module
to create a new module- call
ng g component new-module/new-component
This should add the new component
, directive
or pipe
reference to the new-module
you've created.
To update Angular CLI to a new version, you must update both the global package and your project's local package.
Global package:
npm uninstall -g @angular/cli
npm cache verify
If npm version is < 5 then use npm cache clean
npm install -g @angular/cli@latest
Local project package:
rm -rf node_modules dist
Use rmdir /S/Q node_modules dist in Windows Command Prompt; use rm -r -fo node_modules,dist in Windows PowerShell
npm install --save-dev @angular/cli@latest
npm install
You can find more details about changes between versions in the Releases tab on GitHub.