ng generate command in Angular CLI
ng generate command in Angular CLI is one of the building blocks of Angular applications.
The core Angular application files(or schematics) are created using ng generate command.
ng generate command syntax
The syntax of ng generate command is pretty straight forward, we have to pass schematic and schematic name as an argument.
Additionally we can pass different options as well.
ng generate <schematic> [options]
ng generate command arguments
ng generate takes one argument i.e, schematic.
The schematic type is string.
ng generate command options
ng generate command accepts 5 different types of options.
- defaults
 - dry-run
 - force
 - help
 - interactive
 
| Option | Description | Type | Default Value | 
|---|---|---|---|
| defaults | Disable interactive input prompts for options with a default | boolean | false | 
| dry-run | Run through and reports activity without writing out results. | boolean | false | 
| force | Force overwriting of existing files. | boolean | false | 
| help | Shows a help message for this command in the console. | boolean | false | 
| interactive | Enable interactive input prompts. | boolean | true | 
ng generate example
For example if you want to create a component named product, use ng generate component product command.
CREATE src/app/product/product.component.html (22 bytes)
CREATE src/app/product/product.component.spec.ts (633 bytes)
CREATE src/app/product/product.component.ts (280 bytes)
CREATE src/app/product/product.component.scss (0 bytes)
UPDATE src/app/app.module.ts (1039 bytes)
List of files created using ng generate command.
Here are the list of files or schematics can be created using ng generate command.
- ng generate component
 - ng generate pipe
 - ng generate class
 - ng generate interface
 - ng generate enum
 - ng generate service
 - ng generate library
 - ng generate module
 - ng generate application
 - ng generate app-shell
 - ng generate directive
 - ng generate guard
 - ng generate interceptor
 - ng generate resolver
 - ng generate service-worker
 - ng generate web-worker
 
