How to use the Angular CLI generate command line
Creates a new, generic NgModule definition in the given or default project.
CREATE src/app/page/edit/edit.module.ts (190 bytes)
Creates a new, generic component definition in the given or default project.
CREATE src/app/page/edit/edit.component.scss (0 bytes) CREATE src/app/page/edit/edit.component.html (19 bytes) CREATE src/app/page/edit/edit.component.spec.ts (612 bytes) CREATE src/app/page/edit/edit.component.ts (268 bytes) UPDATE src/app/page/edit/edit.module.ts (261 bytes)
The Angular CLI generate Help Commands and Options
Usage:
ng generate <schematic> [options]
ng g <schematic> [options]
Arguments:
<schematic>The schematic or collection:schematic to generate.This option can take one of the following sub-commands:app-shell、application、class、component、directive、enum、guard、interceptor、interface、library、module、pipe、resolver、service、service-worker、web-workerOptions:
--defaultsDisable interactive input prompts for options with a default.--dry-run default:falseRun through and reports activity without writing out results. Aliases: -d--force default:falseForce overwriting of existing files. Aliases: -f--help default:falseShows a help message for this command in the console.--interactiveEnable interactive input prompts.
Schematic commands: app-shell
Generates an app shell for running a server-side version of an app.
Usage:
ng generate app-shell [options]
ng g app-shell [options]
Options:
--app-dir default:appThe name of the application directory.--app-id default:serverAppThe app ID to use in withServerTransition().--main default:main.server.tsThe name of the main entry-point file.--projectThe name of the related client app.--root-module-class-name default:AppServerModuleThe name of the root module class.--root-module-file-name default:app.server.module.tsThe name of the root module file--route default:shellRoute path used to produce the app shell.
Schematic commands: application
Generates a new basic app definition in the "projects" subfolder of the workspace.
Usage:
ng generate application <name> [options]
ng g application <name> [options]
Arguments:
<name>The name of the new app.Options:
--inline-styleInclude 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. Aliases: -s--inline-templateInclude 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. Aliases: -t--legacy-browsers default:falseDeprecated: Legacy browsers support is deprecated since version 12.--lint-fixDeprecated: Use "ng lint --fix" directly instead. Apply lint fixes after generating the application.--minimal default:falseCreate a bare-bones project without any testing frameworks. (Use for learning purposes only.)--prefix default:appA prefix to apply to generated selectors. Aliases: -p--routing default:falseCreate a routing NgModule.--skip-install default:falseSkip installing dependency packages.--skip-package-json default:falseDo not add dependencies to the "package.json" file.--skip-tests default:falseDo not create "spec.ts" test files for the application. Aliases: -S--strict default:trueCreates an application with stricter bundle budgets settings.--style default:cssThe file extension or preprocessor to use for style files.--view-encapsulationThe view encapsulation strategy to use in the new app.
Schematic commands: class
Creates a new, generic class definition in the given or default project.
Usage:
ng generate class <name> [options]
ng g class <name> [options]
Arguments:
<name>The name of the new class.Options:
--lint-fix default:falseDeprecated: Use "ng lint --fix" directly instead. Apply lint fixes after generating the class.--projectThe name of the project.--skip-tests default:falseDo not create "spec.ts" test files for the new class.--typeAdds a developer-defined type to the filename, in the format "name.type.ts".
Schematic commands: component
Creates a new, generic class definition in the given or default project.
Usage:
ng generate component <name> [options]
ng g component <name> [options]
ng g c <name> [options]
Arguments:
<name>The name of the component.Options:
--change-detection default:DefaultThe change detection strategy to use in the new component. Aliases: -c--display-block default:falseSpecifies if the style will contain :host { display: block; }. Aliases: -b--export default:falseThe declaring NgModule exports this component.--flat default:falseCreate the new files at the top level of the current project.--inline-style default:falseInclude 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. Aliases: -s--inline-template default:falseInclude template inline in the component.ts file. By default, an external template file is created and referenced in the component.ts file. Aliases: -t--lint-fixDeprecated: Use "ng lint --fix" directly instead. Apply lint fixes after generating the component.--moduleThe declaring NgModule. Aliases: -m--prefixThe prefix to apply to the generated component selector. Aliases: -p--projectThe name of the project.--selectorThe HTML selector to use for this component.--skip-import default:falseDo not import this component into the owning NgModule.--skip-selector default:falseSpecifies if the component should have a selector or not.--skip-tests default:falseDo not create "spec.ts" test files for the new component.--style default:cssThe file extension or preprocessor to use for style files.--type default:ComponentAdds a developer-defined type to the filename, in the format "name.type.ts".--view-encapsulationThe view encapsulation strategy to use in the new component. Aliases: -v
Schematic commands: directive
Creates a new, generic directive definition in the given or default project.
Usage:
ng generate directive <name> [options]
ng g directive <name> [options]
Arguments:
<name>The name of the new directive.Options:
--export default:falseThe declaring NgModule exports this directive.--flat default:trueWhen true (the default), creates the new files at the top level of the current project.--lint-fixDeprecated: Use "ng lint --fix" directly instead. Apply lint fixes after generating the directive.--moduleThe declaring NgModule. Aliases: -m--prefixA prefix to apply to generated selectors. Aliases: -p--projectThe name of the project.--selectorThe HTML selector to use for this directive.--skip-import default:falseDo not import this directive into the owning NgModule.--skip-tests default:falseDo not create "spec.ts" test files for the new class.
Schematic commands: enum
Generates a new, generic enum definition for the given or default project.
Usage:
ng generate enum <name> [options]
ng g enum <name> [options]
Arguments:
<name>The name of the enum.Options:
--lint-fixDeprecated: Use "ng lint --fix" directly instead. Apply lint fixes after generating the enum.--projectThe name of the project in which to create the enum. Default is the configured default project for the workspace.--typeAdds a developer-defined type to the filename, in the format "name.type.ts".
Schematic commands: guard
Generates a new, generic route guard definition in the given or default project.
Usage:
ng generate guard <name> [options]
ng g guard <name> [options]
Arguments:
<name>The name of the new route guard.Options:
--flat default:trueWhen true (the default), creates the new files at the top level of the current project.--implementsSpecifies which interfaces to implement.--lint-fixDeprecated: Use "ng lint --fix" directly instead. Apply lint fixes after generating the guard.--projectThe name of the project.--skip-tests default:falseDo not create "spec.ts" test files for the new guard.
Schematic commands: interceptor
Creates a new, generic interceptor definition in the given or default project.
Usage:
ng generate interceptor <name> [options]
ng g interceptor <name> [options]
Arguments:
<name>The name of the interceptor.Options:
--flat default:trueWhen true (the default), creates files at the top level of the project.--lint-fixDeprecated: Use "ng lint --fix" directly instead. Apply lint fixes after generating the interceptor.--projectThe name of the project.--skip-tests default:falseDo not create "spec.ts" test files for the new interceptor.
Schematic commands: interface
Creates a new, generic interface definition in the given or default project.
Usage:
ng generate interface <name> <type> [options]
ng g interface <name> <type> [options]
Arguments:
<name>The name of the interface.<type>Adds a developer-defined type to the filename, in the format "name.type.ts".Options:
--lint-fixDeprecated: Use "ng lint --fix" directly instead. Apply lint fixes after generating the interface.--prefixA prefix to apply to generated selectors.--projectThe name of the project.
Schematic commands: library
Creates a new, generic library project in the current workspace.
Usage:
ng generate library <name> [options]
ng g library <name> [options]
Arguments:
<name>The name of the library.Options:
--entry-file default:public-apiThe path at which to create the library's public API file, relative to the workspace root.--lint-fixDeprecated: Use "ng lint --fix" directly instead. Apply lint fixes after generating the library.--prefix default:libA prefix to apply to generated selectors. Aliases: -p--skip-install default:falseDo not install dependency packages.--skip-package-json default:falseDo not add dependencies to the "package.json" file.--skip-ts-config default:falseDo 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.
Schematic commands: module
Creates a new, generic NgModule definition in the given or default project.
Usage:
ng generate module <name> [options]
ng g module <name> [options]
ng g m <name> [options]
Arguments:
<name>The name of the NgModule.Options:
--flat default:falseCreate the new files at the top level of the current project root.--lint-fixDeprecated: Use "ng lint --fix" directly instead. Apply lint fixes after generating the module.--moduleThe declaring NgModule. Aliases: -m--projectThe name of the project.--routeThe 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 Routes array declared in the module provided in the --module option.--routing default:falseCreate a routing module.--routing-scope default:ChildThe scope for the new routing module.
Schematic commands: pipe
Creates a new, generic pipe definition in the given or default project.
Usage:
ng generate pipe <name> [options]
ng g pipe <name> [options]
Arguments:
<name>The name of the pipe.Options:
--export default:falseThe declaring NgModule exports this pipe.--flat default:trueWhen true (the default) creates files at the top level of the project.--lint-fix default:falseDeprecated: Use "ng lint --fix" directly instead. Apply lint fixes after generating the pipe.--moduleThe declaring NgModule. Aliases: -m--projectThe name of the project.--skip-import default:falseDo not import this pipe into the owning NgModule.--skip-tests default:falseDo not create "spec.ts" test files for the new pipe.
Schematic commands: resolver
Generates a new, generic resolver definition in the given or default project.
Usage:
ng generate resolver <name> [options]
ng g resolver <name> [options]
Arguments:
<name>The name of the new resolver.Options:
--flat default:trueWhen true (the default), creates the new files at the top level of the current project.--projectThe name of the project.--skip-tests default:falseDo not create "spec.ts" test files for the new resolver.
Schematic commands: service
Creates a new, generic service definition in the given or default project.
Usage:
ng generate service <name> [options]
ng g service <name> [options]
Arguments:
<name>The name of the service.Options:
--flat default:trueWhen true (the default), creates files at the top level of the project.--lint-fixDeprecated: Use "ng lint --fix" directly instead. Apply lint fixes after generating the service.--projectThe name of the project.--skip-tests default:falseDo not create "spec.ts" test files for the new service.
Schematic commands: service-worker
Pass this schematic to the "run" command to create a service worker
Usage:
ng generate service-worker [options]
ng g service-worker [options]
Options:
--configurationDeprecated: No longer has an effect. The configuration to apply service worker to.--projectThe name of the project.--target default:buildThe target to apply service worker to.
Schematic commands: web-worker
Creates a new, generic web worker definition in the given or default project.
Usage:
ng generate web-worker <name> [options]
ng g web-worker <name> [options]
Arguments:
<name>The name of the worker.Options:
--projectThe name of the project.--snippet default:trueAdd a worker creation snippet in a sibling file of the same name.--target default:buildDeprecated: No longer has an effect. The target to apply web worker to.