Angular Pipes : Converting the Output
Table of contents
What is Angular Pipes:
Pipes are the converters that are used to transform the output of our templates.
We can use Angular pipes to transform our input to desired outputs for the user interface.
Inbuilt Pipes:
DatePipe
: Formats a date value according to the given format.UpperCasePipe
: Transform the text to Uppercase.LowerCasePipe
: Transform the text to Lowercase.CurrencyPipe
: Transforms a number to a currency string, formatted according to locale rules.DecimalPipe
: Transforms a number into a string with a decimal point, formatted according to locale rules.PercentPipe
: Transforms a number into a string with a decimal point, formatted according to locale rules.
UpperCasePipe:
<div class="container mt-4" *ngFor="let item of servers">
<div [class]="item.serverstate" role="alert">
{{ item.servername }}โ{{item.serverstatus}}
</div>
</div>
import { Component } from '@angular/core';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css']
})
export class HomeComponent {
servers = [
{ servername:'production', serverstatus:'online',serverstate:'alert alert-success' },
{ servername:'database', serverstatus:'offline',serverstate:'alert alert-danger' },
{ servername:'development', serverstatus:'online',serverstate:'alert alert-success' },
{ servername:'client', serverstatus:'online',serverstate:'alert alert-success' },
{ servername:'design', serverstatus:'offline',serverstate:'alert alert-danger' }
]
}
Our application looks something like this.
<div class="container mt-4" *ngFor="let item of servers">
<div [class]="item.serverstate" role="alert">
{{ item.servername | uppercase }}โ{{item.serverstatus | uppercase}}
</div>
</div>
|uppercase
lowercase
operation likewise.Subscribe to my newsletter
Read articles from Arpita Priyadarshini Sahoo directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by