Angular has many built-in pipes, such as date, async, currency, etc. Although it is ready to use, it is far from meeting some business needs, so it is necessary to implement some customized pipes.
The most basic custom pipe is to receive one value and then return another value. The form of the argument is not limited, it can be any type such as string, number, object, etc.
Formatting the pipeline on the default date will not meet our needs.
JSON result returned by the interface:
{"statusDate":"0001-01-01T00:00:00" ...} This is due to the fact that we serialize objects in .NET Core and attach a default value to a field of type datetime, which is DateTime.MinValue.
We use
will be displayed
ourThe requirement is that if a field of type datetime is returned, if it is empty, i.e. "0001-01-01T00:00:00", it needs to return NA。
Let's create a new pipeline through the angular-cli command, the command is as follows:
The code is as follows:
After the new creation is completed, the app.module.ts file will automatically add the following code:
We're back using the new pipeline on the HTML page, as follows:
will return, and the result we want, as shown in the image below:
Note: Passing parameters to pip uses : splitting.
|