This article is a mirror article of machine translation, please click here to jump to the original article.

View: 16963|Reply: 1

[Angular] Angular 9 Series (IV) Custom Pipe pipelines

[Copy link]
Posted on 6/3/2020 2:03:29 PM | | | |
Angular 9 Series (1) Dynamically Loaded Components
https://www.itsvse.com/thread-9238-1-1.html

Angular 9 series (2) dynamic component transmission parameters
https://www.itsvse.com/thread-9245-1-1.html

Angular 9 series (3) subscribes to dynamic component events
https://www.itsvse.com/thread-9246-1-1.html

Angular 9 Series (IV) Custom Pipe pipelines
https://www.itsvse.com/thread-9248-1-1.html

Angular 9 Series (V) formats the amount currency format
https://www.itsvse.com/thread-9249-1-1.html


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

01-Jan-0001

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.




Previous:Article publishing system who knows how to write
Next:Angular 9 Series (V) formats the amount currency format
Posted on 10/28/2022 1:52:07 PM |
Learn!!!!!!!!!!!
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com