ng generate
Generates and/or modifies files based on a schematic.
ng generate <schematic> [options]
ng g <schematic> [options]
Arguments
Argument | Description |
---|---|
<schematic> | The schematic or collection:schematic to generate. This option can take one of the following sub-commands: |
Options
Option | Description |
---|---|
--defaults=true|false | When true, disables interactive input prompts for options with a default. |
--dryRun=true|false | When true, runs through and reports activity without writing out results. Default: Aliases: -d |
--force=true|false | When true, forces overwriting of existing files. Default: Aliases: -f |
--help= true|false|json|JSON | Shows a help message for this command in the console. Default: |
--interactive=true|false | When false, disables interactive input prompts. |
Schematic commands
appShell
ng generate appShell [options]
ng g appShell [options]
Generates an app shell for running a server-side version of an app.
Options
Option | Description |
---|---|
--appDir=appDir | The name of the application directory. Default: |
--appId=appId | The app ID to use in withServerTransition(). Default: |
--clientProject=clientProject | The name of the related client app. |
--index=index | The name of the index file Default: |
--main=main | The name of the main entry-point file. Default: |
--name=name | The HTML selector of the Universal app |
--outDir=outDir | The output directory for build results. Default: |
--root=root | The root directory of the app. Default: |
--rootModuleClassName= rootModuleClassName | The name of the root module class. Default: |
--rootModuleFileName= rootModuleFileName | The name of the root module file Default: |
--route=route | Route path used to produce the app shell. Default: |
--sourceDir=sourceDir | The path of the source directory. Default: Aliases: -D |
--test=test | The name of the test entry-point file. |
--testTsconfigFileName= testTsconfigFileName | The name of the TypeScript configuration file for tests. Default: |
--tsconfigFileName= tsconfigFileName | The name of the TypeScript configuration file. Default: |
--universalProject= universalProject | The name of related Universal app. |
application
ng generate application <name> [options]
ng g application <name> [options]
Generates a new basic app definition in the "projects" subfolder of the workspace.
Arguments
Argument | Description |
---|---|
<name> | The name of the new app. |
Options
Option | Description |
---|---|
--enableIvy=true|false | EXPERIMENTAL True to create a new app that uses the Ivy rendering engine. Default: |
--inlineStyle=true|false | When true, includes styles inline in the root component.ts file. Only CSS styles can be included inline. Default is false, meaning that an external styles file is created and referenced in the root component.ts file. Default: Aliases: -s |
--inlineTemplate=true|false | When true, includes template inline in the root component.ts file. Default is false, meaning that an external template file is created and referenced in the root component.ts file. Default: Aliases: -t |
--lintFix=true|false | When true, applies lint fixes after generating the application. Default: |
--minimal=true|false | When true, creates a bare-bones project without any testing frameworks. (Use for learning purposes only.) Default: |
--prefix=prefix | A prefix to apply to generated selectors. Default: Aliases: -p |
--routing=true|false | When true, creates a routing NgModule. Default: |
--skipInstall=true|false | Skip installing dependency packages. Default: |
--skipPackageJson=true|false | When true, does not add dependencies to the "package.json" file. Default: |
--skipTests=true|false | When true, does not create "spec.ts" test files for the app. Default: Aliases: -S |
--style= css|scss|sass|less|styl | The file extension or preprocessor to use for style files. Default: |
--viewEncapsulation= Emulated|Native|None|ShadowDom | The view encapsulation strategy to use in the new app. |
class
ng generate class <name> [options]
ng g class <name> [options]
Creates a new generic class definition in the given or default project.
Arguments
Argument | Description |
---|---|
<name> | The name of the new class. |
Options
Option | Description |
---|---|
--lintFix=true|false | When true, applies lint fixes after generating the class. Default: |
--project=project | The name of the project. |
--skipTests=true|false | When true, does not create "spec.ts" test files for the new class. Default: |
--spec=true|false | Deprecated: Use "skipTests" instead. When true (the default), generates a "spec.ts" test file for the new class. Default: |
--type=type | Adds a developer-defined type to the filename, in the format "name.type.ts". Default: |
component
ng generate component <name> [options]
ng g component <name> [options]
Creates a new generic component definition in the given or default project.
Arguments
Argument | Description |
---|---|
<name> | The name of the component. |
Options
Option | Description |
---|---|
--changeDetection=Default|OnPush | The change detection strategy to use in the new component. Default: Aliases: -c |
--entryComponent=true|false | When true, the new component is the entry component of the declaring NgModule. Default: |
--export=true|false | When true, the declaring NgModule exports this component. Default: |
--flat=true|false | When true, creates the new files at the top level of the current project. Default: |
--inlineStyle=true|false | When true, includes styles inline in the component.ts file. Only CSS styles can be included inline. By default, an external styles file is created and referenced in the component.ts file. Default: Aliases: -s |
--inlineTemplate=true|false | When true, includes template inline in the component.ts file. By default, an external template file is created and referenced in the component.ts file. Default: Aliases: -t |
--lintFix=true|false | When true, applies lint fixes after generating the component. Default: |
--module=module | The declaring NgModule. Aliases: -m |
--prefix=prefix | The prefix to apply to the generated component selector. Aliases: -p |
--project=project | The name of the project. |
--selector=selector | The HTML selector to use for this component. |
--skipImport=true|false | When true, does not import this component into the owning NgModule. Default: |
--skipSelector=true|false | Specifies if the component should have a selector or not. Default: |
--skipTests=true|false | When true, does not create "spec.ts" test files for the new component. Default: |
--spec=true|false | Deprecated: Use "skipTests" instead. When true (the default), generates a "spec.ts" test file for the new component. Default: |
--style= css|scss|sass|less|styl | The file extension or preprocessor to use for style files. Default: |
--styleext=styleext | Deprecated: Use "style" instead. The file extension to use for style files. Default: |
--viewEncapsulation= Emulated|Native|None|ShadowDom | The view encapsulation strategy to use in the new component. Aliases: -v |
directive
ng generate directive <name> [options]
ng g directive <name> [options]
Creates a new generic directive definition in the given or default project.
Arguments
Argument | Description |
---|---|
<name> | The name of the new directive. |
Options
Option | Description |
---|---|
--export=true|false | When true, the declaring NgModule exports this directive. Default: |
--flat=true|false | When true (the default), creates the new files at the top level of the current project. Default: |
--lintFix=true|false | When true, applies lint fixes after generating the directive. Default: |
--module=module | The declaring NgModule. Aliases: -m |
--prefix=prefix | A prefix to apply to generated selectors. Aliases: -p |
--project=project | The name of the project. |
--selector=selector | The HTML selector to use for this directive. |
--skipImport=true|false | When true, does not import this directive into the owning NgModule. Default: |
--skipTests=true|false | When true, does not create "spec.ts" test files for the new class. Default: |
--spec=true|false | Deprecated: Use "skipTests" instead. When true (the default), generates a "spec.ts" test file for the new directive. Default: |
enum
ng generate enum <name> [options]
ng g enum <name> [options]
Generates a new, generic enum definition for the given or default project.
Arguments
Argument | Description |
---|---|
<name> | The name of the enum. |
Options
Option | Description |
---|---|
--lintFix=true|false | When true, applies lint fixes after generating the enum. Default: |
--project=project | The name of the project in which to create the enum. Default is the configured default project for the workspace. |
guard
ng generate guard <name> [options]
ng g guard <name> [options]
Generates a new, generic route guard definition in the given or default project.
Arguments
Argument | Description |
---|---|
<name> | The name of the new route guard. |
Options
Option | Description |
---|---|
--flat=true|false | When true (the default), creates the new files at the top level of the current project. Default: |
--implements | Specifies which interfaces to implement. |
--lintFix=true|false | When true, applies lint fixes after generating the guard. Default: |
--project=project | The name of the project. |
--skipTests=true|false | When true, does not create "spec.ts" test files for the new guard. Default: |
--spec=true|false | Deprecated: Use "skipTests" instead. When true (the default), generates a "spec.ts" test file for the new guard. Default: |
interface
ng generate interface <name> <type> [options]
ng g interface <name> <type> [options]
Creates a new generic interface definition in the given or default project.
Arguments
Argument | Description |
---|---|
<name> | The name of the interface. |
<type> | Adds a developer-defined type to the filename, in the format "name.type.ts". |
Options
Option | Description |
---|---|
--lintFix=true|false | When true, applies lint fixes after generating the interface. Default: |
--prefix=prefix | A prefix to apply to generated selectors. Default: |
--project=project | The name of the project. |
library
ng generate library <name> [options]
ng g library <name> [options]
Creates a new generic library project in the current workspace.
Arguments
Argument | Description |
---|---|
<name> | The name of the library. |
Options
Option | Description |
---|---|
--entryFile=entryFile | The path at which to create the library's public API file, relative to the workspace root. Default: |
--lintFix=true|false | When true, applies lint fixes after generating the library. Default: |
--prefix=prefix | A prefix to apply to generated selectors. Default: Aliases: -p |
--skipInstall=true|false | When true, does not install dependency packages. Default: |
--skipPackageJson=true|false | When true, does not add dependencies to the "package.json" file. Default: |
--skipTsConfig=true|false | When true, does not update "tsconfig.json" to add a path mapping for the new library. The path mapping is needed to use the library in an app, but can be disabled here to simplify development. Default: |
module
ng generate module <name> [options]
ng g module <name> [options]
Creates a new generic NgModule definition in the given or default project.
Arguments
Argument | Description |
---|---|
<name> | The name of the NgModule. |
Options
Option | Description |
---|---|
--flat=true|false | When true, creates the new files at the top level of the current project root. Default: |
--lintFix=true|false | When true, applies lint fixes after generating the module. Default: |
--module=module | The declaring NgModule. Aliases: -m |
--project=project | The name of the project. |
--route=route | The route path for a lazy-loaded module. When supplied, creates a component in the new module, and adds the route to that component in the |
--routing=true|false | When true, creates a routing module. Default: |
--routingScope=Child|Root | The scope for the new routing module. Default: |
pipe
ng generate pipe <name> [options]
ng g pipe <name> [options]
Creates a new generic pipe definition in the given or default project.
Arguments
Argument | Description |
---|---|
<name> | The name of the pipe. |
Options
Option | Description |
---|---|
--export=true|false | When true, the declaring NgModule exports this pipe. Default: |
--flat=true|false | When true (the default) creates files at the top level of the project. Default: |
--lintFix=true|false | When true, applies lint fixes after generating the pipe. Default: |
--module=module | The declaring NgModule. Aliases: -m |
--project=project | The name of the project. |
--skipImport=true|false | When true, does not import this pipe into the owning NgModule. Default: |
--skipTests=true|false | When true, does not create "spec.ts" test files for the new pipe. Default: |
--spec=true|false | Deprecated: Use "skipTests" instead. When true (the default), generates a "spec.ts" test file for the new pipe. Default: |
service
ng generate service <name> [options]
ng g service <name> [options]
Creates a new, generic service definition in the given or default project.
Arguments
Argument | Description |
---|---|
<name> | The name of the service. |
Options
Option | Description |
---|---|
--flat=true|false | When true (the default), creates files at the top level of the project. Default: |
--lintFix=true|false | When true, applies lint fixes after generating the service. Default: |
--project=project | The name of the project. |
--skipTests=true|false | When true, does not create "spec.ts" test files for the new service. Default: |
--spec=true|false | Deprecated: Use "skipTests" instead. When true (the default), generates a "spec.ts" test file for the new service. Default: |
serviceWorker
ng generate serviceWorker [options]
ng g serviceWorker [options]
Pass this schematic to the "run" command to create a service worker
Options
Option | Description |
---|---|
--configuration=configuration | The configuration to apply service worker to. Default: |
--project=project | The name of the project. |
--target=target | The target to apply service worker to. Default: |
universal
ng generate universal [options]
ng g universal [options]
Pass this schematic to the "run" command to set up server-side rendering for an app.
Options
Option | Description |
---|---|
--appDir=appDir | The name of the application folder. Default: |
--appId=appId | The app identifier to use for transition. Default: |
--clientProject=clientProject | The name of the related client app. Required in place of "project". |
--main=main | The name of the main entry-point file. Default: |
--rootModuleClassName= rootModuleClassName | The name of the root NgModule class. Default: |
--rootModuleFileName= rootModuleFileName | The name of the root NgModule file. Default: |
--skipInstall=true|false | When true, does not install packages for dependencies. Default: |
--test=test | The name of the test entry-point file. |
--testTsconfigFileName= testTsconfigFileName | The name of the TypeScript configuration file for tests. Default: |
--tsconfigFileName= tsconfigFileName | The name of the TypeScript configuration file. Default: |
webWorker
ng generate webWorker <name> [options]
ng g webWorker <name> [options]
Creates a new generic web worker definition in the given or default project.
Arguments
Argument | Description |
---|---|
<name> | The name of the worker. |
Options
Option | Description |
---|---|
--project=project | The name of the project. |
--snippet=true|false | Add a worker creation snippet in a sibling file of the same name. Default: |
--target=target | The target to apply web worker to. Default: |
© 2010–2020 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://v8.angular.io/cli/generate