Friday, 28 December 2018

How to create a Pipe in angular ?

To create a directive:

ng generate pipe PipeName

Or

ng g p PipeName

If your angular application contains multiple modules you will get an error because Angular CLI does not know with which module the newly generated Pipe should be registered.

To avoid this you can use 

ng g p PipeName--skip-import

Angular CLI don't import and register the generated Pipe with any module.

Or you can use below command to tell the angular cli with which module it should register when multiple modules are present in your application.

ng g p PipeName -m=app.module

In the above, it will register to the app module in your angular application

You can use --flat option to create a dedicated folder for the Pipe.
You can use --spec to specifies if a spec file should be generated or not by passing true or false value.

No comments:

Post a Comment