PrefacePIPE, translated as pipeline. Angular pipes are a way to write transformations of display values that can be declared in HTML components. Angular pipes were previously called filters in AngularJS and are now called pipes since Angular 2. A pipeline takes data as input and transforms it into the desired output. Angular Pipes takes integers, strings, arrays, and dates as input separated by | and then converts them into the required format and displays them in the browser. In interpolation expressions, you can define pipes and use them as appropriate. There are many types of pipes that you can use in an Angular application. Built-in pipeline
How to useUppercase conversion <div> <p ngNonBindable>{{ 'Angular' | uppercase }}</p> <p>{{ 'Angular' | uppercase }}</p> <!-- Output: ANGULAR --> </div> Date formatting <div> <p ngNonBindable>{{ today | date: 'shortTime' }}</p> <p>{{ today | date: 'shortTime' }}</p> <!-- Output: Based on the current time, output format: 10:40 AM --> </div> Numeric formatting <div> <p ngNonBindable>{{ 3.14159265 | number: '1.4-4' }}</p> <p>{{ 3.14159265 | number: '1.4-4' }}</p> <!-- Output: 3.1416 --> </div> JavaScript Object Serialization <div> <p ngNonBindable>{{ { name: 'semlinker' } | json }}</p> <p>{{ { name: 'semlinker' } | json }}</p> <!-- Output: { "name": "semlinker" } --> </div> Pipeline parameters A pipeline can accept any number of parameters by appending : and the parameter value after the pipeline name. For example, number: '1.4-4'. If you need to pass multiple parameters, separate them with colons. The specific examples are as follows: <div> <p ngNonBindable>{{ 'semlinker' | slice:0:3 }}</p> <p>{{ 'semlinker' | slice:0:3 }}</p> <!-- Output: sem --> </div> Pipeline Chain <div> <p ngNonBindable>{{ 'semlinker' | slice:0:3 | uppercase }}</p> <p>{{ 'semlinker' | slice:0:3 | uppercase }}</p> </div> Custom pipelineThe following uses the pipeline used in previous projects as an example to explain the steps of customizing the pipeline:
definition import { Pipe, PipeTransform } from "@angular/core"; @Pipe({ name: "formatError" }) export class FormatErrorPipe implements PipeTransform { constructor() {} transform(value: any, module: string) { if (value.code) { return value.desc; } else { return value.message; } } } use <div *ngIf="errorMessage"> <div class="message-box error mb-16" [@animate]="{value:'*',params:{opacity:'0',duration:'200ms'}}"> {{errorMessage.error | formatError:"auth"}} </div> </div> SummarizeThis is the end of this article about Angular pipe PIPE. For more relevant Angular pipe PIPE content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
>>: Basic JSON Operation Guide in MySQL 5.7
1. First log in to the Alibaba Cloud website to r...
1. How do I remove the blank space of a few pixels...
Table of contents Overview Single file components...
This article tests the environment: CentOS 7 64-b...
need: In background management, there are often d...
Preface Because this is a distributed file system...
Why is it that when the input tag type is file an...
This article uses examples to illustrate the synt...
This article uses examples to explain the concept...
This article shows you how to use CSS to create a...
Make a blank space for Taobao: When you shrink th...
Cerebro is an evolution of the Elasticsearch Kopf...
Preface When a 403 cross-origin error occurs No &...
Purpose: Nested use of MySQL aggregate functions ...
Table of contents Normal loading Lazy Loading Pre...