ng generate pipe command in Angular CLI

ng generate pipe command is used to create pipes in Angular applications

ng generate pipe syntax

ng generate pipe takes pipe name as parameter.

Additionally we can pass different options as well.

ng generate pipe [name] [options]

or you can use shorthand syntax

ng generate p [name] [options]

ng generate pipe arguments

ng generate pipe takes one argument i.e, name, nothing but pipe name.

The name type is string.

ng generate pipe options

ng generate pipe accepts 7 different types of options.

  1. export
  2. flat
  3. module
  4. project
  5. skip-import
  6. skip-tests
  7. standalone
OptionDescriptionTypeDefault Value
exportThe declaring NgModule exports this pipe.booleanfalse
flatWhen true (the default), creates the new files at the top level of the current project.booleantrue
moduleThe declaring NgModule. Aliases: -mstring
projectThe name of the project.string
skip-importDo not import this pipe into the owning NgModule.booleanfalse
skip-testsDo not create "spec.ts" test files for the new pipe.booleanfalse
standaloneWhether the generated pipe is standalone.booleanfalse

ng generate pipe example

For example if you want to create a pipe named square, use ng generate pipe square command.

CREATE src/app/square.pipe.spec.ts (187 bytes)
CREATE src/app/square.pipe.ts (217 bytes)
UPDATE src/app/app.module.ts (2931 bytes)
Avatar

Arunkumar Gudelli

Liked this post? Subscribe