- Angular CLI - Code Coverage
- Angular CLI - ng xi18n
- Angular CLI - ng update
- Angular CLI - ng doc
- Angular CLI - ng config
- Angular CLI - ng analytics
- Angular CLI - ng add
- Angular CLI - ng e2e
- Angular CLI - ng test
- Angular CLI - ng lint
- Angular CLI - ng serve
- Angular CLI - ng run
- Angular CLI - ng build
- Angular CLI - ng generate
- Angular CLI - ng help
- Angular CLI - ng new
- Angular CLI - ng version
- Angular CLI - Environment Setup
- Angular CLI - Overview
- Angular CLI - Home
Angular CLI Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Angular CLI - ng generate Command
This chapter explains the syntax, argument and options of ng generate command along with an example.
Syntax
The syntax for ng generate command is as follows −
ng generate <schematic> [options] ng g <schematic> [options]
ng generate command generates and/or modifies files based on a schematic.
Argument
The argument for ng help command is as follows −
Sr.No. | Argument & Syntax | Description |
---|---|---|
1 | <schematic> | The schematicor collection:schematic to generate. This option can take one ofthe following sub-commands:
appShell apppcation class component directive enum guard interceptor interface pbrary module pipe service serviceWorker webWorker |
Options
Options are optional parameters.
Sr.No. | Option & Syntax | Description |
---|---|---|
1 | --defaults=true|false | When true, disables interactive input prompts for options witha default. |
2 | --dryRun=true|false | When true,runs through and reports activity without writing out results. Default:false. Apases: -d. |
3 | --force=true|false | When true,forces overwriting of existing files. Default:false. Apases: -f. |
4 | --help=true|false|json|JSON | Shows a helpmessage for this command in the console. Default: false. |
5 | --interactive=true|false | When false, disables interactive input prompts. |
First move to an angular project created using ng new command and then run the command. This chapter is available at
Example
An example for ng generate command is given below −
>Node>TutorialsPoint> ng generate component goals CREATE src/app/goals/goals.component.html (20 bytes) CREATE src/app/goals/goals.component.spec.ts (621 bytes) CREATE src/app/goals/goals.component.ts (271 bytes) CREATE src/app/goals/goals.component.css (0 bytes) UPDATE src/app/app.module.ts (471 bytes)
Here, ng generate command has created a new component in our project TutorialsPoint and added this new component entry in app.module.ts.
Advertisements