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.
- export
- flat
- module
- project
- skip-import
- skip-tests
- standalone
| Option | Description | Type | Default Value |
|---|---|---|---|
| export | The declaring NgModule exports this pipe. | boolean | false |
| flat | When true (the default), creates the new files at the top level of the current project. | boolean | true |
| module | The declaring NgModule. Aliases: -m | string | |
| project | The name of the project. | string | skip-import | Do not import this pipe into the owning NgModule. | boolean | false |
| skip-tests | Do not create "spec.ts" test files for the new pipe. | boolean | false |
| standalone | Whether the generated pipe is standalone. | boolean | false |
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)