How to create a Pipe?

Execute commands in folders

ng generate pipe name --flat
Copy the code

This command creates a xxxx.pipe.ts file and a xxxx.pipe.spec.ts file in the folder. The spec.ts file is used for testing and is not available. The logic is written in pipe.ts. Here’s an example.









Pipe





Also need to mention this: if you use presents module with pipe such as date, type of its parameters must not be errors, such as the {{time | date: yyyy – MM – DD HH: Mm time if a certain number of ss ‘}} | | Date can’t be a string, or presents will throw an error.

The end.