Angular CLI – ng generate Command

Angular CLI - ng generate Command

In this Angular CLI ng generate Command chapter we explain the syntax, argument, and options of ng generate command along with an example. So all Angular CLI ng generate Command listed below-

Syntax

The syntax for the 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 & SyntaxDescription
1<schematic>The schematicor collection:schematic to generate. This option can take one ofthe following sub-commands:appShell
application
class
component
directive
enum
guard
interceptor
interface
library
module
pipe
service
serviceWorker
webWorker

Options

Options are optional parameters.

Sr.No.Option & SyntaxDescription
1–defaults=true|falseWhen true, disables interactive input prompts for options with a default.
2–dryRun=true|falseWhen true, runs through and reports activity without writing out results.Default:false.Aliases: -d.
3–force=true|falseWhen true,forces overwriting of existing files.Default:false.Aliases: -f.
4–help=true|false|json|JSONShows a help message for this command in the console. Default: false.
5–interactive=true|falseWhen 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 https://adglob.in/blog/angular-cli-ng-new-command/.

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.

Next Topic : Click Here

This Post Has 2 Comments

Leave a Reply