NG Generate
Angular - ng generate reference
The Angular CLI command ng generate
is used to generate new code files for an Angular application. The ng generate
command can create new components, services, directives, pipes, modules, classes, interfaces, enums, and guards based on Angular’s best practices and conventions. Using ng generate
can save developers time and effort by automatically generating the boilerplate code needed to create new application features.
Here’s an updated table with a more detailed description of what each ng generate
action is used for:
Here’s the updated table sorted alphabetically by ng generate
action:
ng generate XXXX
Action | Description |
---|---|
application | Generates a new Angular application. This ng generate action is used to create a new, empty Angular application with a basic file structure and configuration. |
class | Generates a new class. This is a general-purpose ng generate action that can be used to create any kind of class in an Angular application. |
component | Generates a new component with a template and styles. This is one of the most commonly used ng generate actions and is used to quickly generate new components for an Angular application. |
directive | Generates a new directive. Directives are used to modify the behavior of an HTML element, component, or another directive. |
enum | Generates a new enum. Enums are used to define a set of named constants in an Angular application, such as defining the possible values of a user’s status. |
guard | Generates a new guard. Guards are used to control access to routes in an Angular application, based on conditions such as whether the user is logged in. |
interface | Generates a new interface. Interfaces are used to define the shape of data in an Angular application, such as defining the properties of a user object. |
library | Generates a new Angular library project. This ng generate action is used to create a new Angular library project that can be shared across multiple applications or modules. |
module | Generates a new NgModule. NgModule s are used to organize an Angular application into cohesive blocks of functionality. |
pipe | Generates a new pipe. Pipes are used to transform data in an Angular application, such as formatting dates or currency values. |
service | Generates a new service class. Services are used to provide functionality that can be shared across components in an Angular application, such as data retrieval or data manipulation. |
ng generate -Usage
Action | Description |
---|---|
class-usage | Generates a new class usage example. This ng generate action is used to create an example usage of a specific class, which can be useful for testing or demonstration purposes. |
component-usage | Generates a new component usage example. This ng generate action is used to create an example usage of a specific component, which can be useful for testing or demonstration purposes. |
directive-usage | Generates a new directive usage example. This ng generate action is used to create an example usage of a specific directive, which can be useful for testing or demonstration purposes. |
enum-usage | Generates a new enum usage example. This ng generate action is used to create an example usage of a specific enum, which can be useful for testing or demonstration purposes. |
interface-usage | Generates a new interface usage example. This ng generate action is used to create an example usage of a specific interface, which can be useful for testing or demonstration purposes. |
module-usage | Generates a new module usage example. This ng generate action is used to create an example usage of a specific NgModule , which can be useful for testing or demonstration purposes. |
pipe-usage | Generates a new pipe usage example. This `ng |
Note that these tables are not exhaustive and there may be other ng generate
actions available depending on the specific version of Angular CLI that you are using.