Help Angular by taking a 1 minute survey!Go to surveyHome

ng generate

Generates and/or modifies files based on a schematic.

ng generate <schematic> [options]
      
      ng generate <schematic> [options]
    
ng g <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: false

Aliases: -d

--force=true|false

When true, forces overwriting of existing files.

Default: false

Aliases: -f

--help=
true|false|json|JSON

Shows a help message for this command in the console.

Default: false

--interactive=true|false

When false, disables interactive input prompts.

Schematic commands

appShell

ng generate appShell [options]
      
      ng generate appShell [options]
    
ng g 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: app

--appId=appId

The app ID to use in withServerTransition().

Default: serverApp

--clientProject=clientProject

The name of the related client app.

--index=index

The name of the index file

Default: index.html

--main=main

The name of the main entry-point file.

Default: main.server.ts

--name=name

The HTML selector of the Universal app

--outDir=outDir

The output directory for build results.

Default: dist-server

--root=root

The root directory of the app.

Default: src

--rootModuleClassName=
rootModuleClassName

The name of the root module class.

Default: AppServerModule

--rootModuleFileName=
rootModuleFileName

The name of the root module file

Default: app.server.module.ts

--route=route

Route path used to produce the app shell.

Default: shell

--sourceDir=sourceDir

The path of the source directory.

Default: src

Aliases: -D

--test=test

The name of the test entry-point file.

--testTsconfigFileName=
testTsconfigFileName

The name of the TypeScript configuration file for tests.

Default: tsconfig.spec

--tsconfigFileName=
tsconfigFileName

The name of the TypeScript configuration file.

Default: tsconfig.server

--universalProject=
universalProject

The name of related Universal app.

application

ng generate application <name> [options]
      
      ng generate application <name> [options]
    
ng g 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: false

--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: false

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: false

Aliases: -t

--lintFix=true|false

When true, applies lint fixes after generating the application.

Default: false

--minimal=true|false

When true, creates a bare-bones project without any testing frameworks. (Use for learning purposes only.)

Default: false

--prefix=prefix

A prefix to apply to generated selectors.

Default: app

Aliases: -p

--routing=true|false

When true, creates a routing NgModule.

Default: false

--skipInstall=true|false

Skip installing dependency packages.

Default: false

--skipPackageJson=true|false

When true, does not add dependencies to the "package.json" file.

Default: false

--skipTests=true|false

When true, does not create "spec.ts" test files for the app.

Default: false

Aliases: -S

--style=
css|scss|sass|less|styl

The file extension or preprocessor to use for style files.

Default: css

--viewEncapsulation=
Emulated|Native|None|ShadowDom

The view encapsulation strategy to use in the new app.

class

ng generate class <name> [options]
      
      ng generate class <name> [options]
    
ng g 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: false

--project=project

The name of the project.

--skipTests=true|false

When true, does not create "spec.ts" test files for the new class.

Default: false

--spec=true|false

Deprecated: Use "skipTests" instead.

When true (the default), generates a "spec.ts" test file for the new class.

Default: true

--type=type

Adds a developer-defined type to the filename, in the format "name.type.ts".

Default:

component

ng generate component <name> [options]
      
      ng generate component <name> [options]
    
ng g 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: Default

Aliases: -c

--entryComponent=true|false

When true, the new component is the entry component of the declaring NgModule.

Default: false

--export=true|false

When true, the declaring NgModule exports this component.

Default: false

--flat=true|false

When true, creates the new files at the top level of the current project.

Default: false

--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: false

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: false

Aliases: -t

--lintFix=true|false

When true, applies lint fixes after generating the component.

Default: false

--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: false

--skipTests=true|false

When true, does not create "spec.ts" test files for the new component.

Default: false

--spec=true|false

Deprecated: Use "skipTests" instead.

When true (the default), generates a "spec.ts" test file for the new component.

Default: true

--style=
css|scss|sass|less|styl

The file extension or preprocessor to use for style files.

Default: css

--styleext=styleext

Deprecated: Use "style" instead.

The file extension to use for style files.

Default: css

--viewEncapsulation=
Emulated|Native|None|ShadowDom

The view encapsulation strategy to use in the new component.

Aliases: -v

directive

ng generate directive <name> [options]
      
      ng generate directive <name> [options]
    
ng g 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: false

--flat=true|false

When true (the default), creates the new files at the top level of the current project.

Default: true

--lintFix=true|false

When true, applies lint fixes after generating the directive.

Default: false

--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: false

--skipTests=true|false

When true, does not create "spec.ts" test files for the new class.

Default: false

--spec=true|false

Deprecated: Use "skipTests" instead.

When true (the default), generates a "spec.ts" test file for the new directive.

Default: true

enum

ng generate enum <name> [options]
      
      ng generate enum <name> [options]
    
ng g 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: false

--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 generate guard <name> [options]
    
ng g 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: true

--implements

Specifies which interfaces to implement.

--lintFix=true|false

When true, applies lint fixes after generating the guard.

Default: false

--project=project

The name of the project.

--skipTests=true|false

When true, does not create "spec.ts" test files for the new guard.

Default: false

--spec=true|false

Deprecated: Use "skipTests" instead.

When true (the default), generates a "spec.ts" test file for the new guard.

Default: true

interface

ng generate interface <name> <type> [options]
      
      ng generate interface <name> <type> [options]
    
ng g 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: false

--prefix=prefix

A prefix to apply to generated selectors.

Default:

--project=project

The name of the project.

library

ng generate library <name> [options]
      
      ng generate library <name> [options]
    
ng g 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: public-api

--lintFix=true|false

When true, applies lint fixes after generating the library.

Default: false

--prefix=prefix

A prefix to apply to generated selectors.

Default: lib

Aliases: -p

--skipInstall=true|false

When true, does not install dependency packages.

Default: false

--skipPackageJson=true|false

When true, does not add dependencies to the "package.json" file.

Default: false

--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: false

module

ng generate module <name> [options]
      
      ng generate module <name> [options]
    
ng g 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: false

--lintFix=true|false

When true, applies lint fixes after generating the module.

Default: false

--module=module

The declaring NgModule.

Aliases: -m

--project=project

The name of the project.

--routing=true|false

When true, creates a routing module.

Default: false

--routingScope=Child|Root

The scope for the new routing module.

Default: Child

pipe

ng generate pipe <name> [options]
      
      ng generate pipe <name> [options]
    
ng g 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: false

--flat=true|false

When true (the default) creates files at the top level of the project.

Default: true

--lintFix=true|false

When true, applies lint fixes after generating the pipe.

Default: false

--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: false

--skipTests=true|false

When true, does not create "spec.ts" test files for the new pipe.

Default: false

--spec=true|false

Deprecated: Use "skipTests" instead.

When true (the default), generates a "spec.ts" test file for the new pipe.

Default: true

service

ng generate service <name> [options]
      
      ng generate service <name> [options]
    
ng g 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: true

--lintFix=true|false

When true, applies lint fixes after generating the pipe.

Default: false

--project=project

The name of the project.

--skipTests=true|false

When true, does not create "spec.ts" test files for the new service.

Default: false

--spec=true|false

Deprecated: Use "skipTests" instead.

When true (the default), generates a "spec.ts" test file for the new service.

Default: true

serviceWorker

ng generate serviceWorker [options]
      
      ng generate serviceWorker [options]
    
ng g 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: production

--project=project

The name of the project.

--target=target

The target to apply service worker to.

Default: build

universal

ng generate universal [options]
      
      ng generate universal [options]
    
ng g 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: app

--appId=appId

The app identifier to use for transition.

Default: serverApp

--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: main.server.ts

--rootModuleClassName=
rootModuleClassName

The name of the root NgModule class.

Default: AppServerModule

--rootModuleFileName=
rootModuleFileName

The name of the root NgModule file.

Default: app.server.module.ts

--skipInstall=true|false

When true, does not install packages for dependencies.

Default: false

--test=test

The name of the test entry-point file.

--testTsconfigFileName=
testTsconfigFileName

The name of the TypeScript configuration file for tests.

Default: tsconfig.spec

--tsconfigFileName=
tsconfigFileName

The name of the TypeScript configuration file.

Default: tsconfig.server

webWorker

ng generate webWorker <name> [options]
      
      ng generate webWorker <name> [options]
    
ng g webWorker <name> [options]
      
      ng g webWorker <name> [options]
    

Pass this schematic to the "run" command to create a Web Worker

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: true

--target=target

The target to apply service worker to.

Default: build