Using the Angular CLI
Angular provides a powerful CLI that makes building out Angular applications a much more streamlined process. By using the CLI, you will quickly be able to generate new Angular applications, components, directives, pipes, and services. The following sections go over some of the most important tools available through the CLI.
Generating Content with the CLI
One of the most common purposes of the CLI is to generate content for applications. It automates the process of creating and bootstrapping a new Angular application, letting you get straight to the meat of the application.
From the command line, run the command ng new [application name] to create a new Angular application. If you navigate to that newly created application, you have access too many other useful commands. Table 3.1 lists some of the most important commands that the CLI has to offer.
Table 3.1 Angular CLI Command Options
Command | Alias | Purpose |
---|---|---|
ng new |
|
Creates a new Angular application |
ng serve |
|
Builds and runs the angular application for testing |
ng eject |
|
Makes the webpack config files available to be edited |
ng generate component [name] |
ng g c [name] |
Creates a new component |
ng generate directive [name] |
ng g d [name] |
Creates a new directive |
ng generate module [name] |
ng g m [name] |
Creates a module |
ng generate pipe [name] |
ng g p [name] |
Creates a pipe |
ng generate service [name] |
ng g s [name] |
Creates a service |
ng generate enum [name] |
ng g e [name] |
Creates an enumeration |
ng generate guard [name] |
ng g g [name] |
Creates a guard |
ng generate interface [name] |
ng g i [name] |
Creates an interface |
While an in-depth guide of everything the CLI has to offer is beyond the scope of this book, it is worth learning how to use.