Open In App

Built-in Pipes in Angular 17

Last Updated : 25 Jun, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Share
Report
News Follow

In theory, pipes are just basic functions that take an input value, process it, and output an altered result. Numerous built-in pipelines are supported by Angular. You can, however, also make custom pipes to meet your needs. Among the noteworthy characteristics are: define pipes with the pipe "|" symbol.

There are several methods to integrate built-in pipes in Angular 17 which are as follows:

Steps to create pipes

Step 1: create an angular project

ng new <YOUR_PROJECT_NAME>

Folder Structure:
Screenshot-from-2024-05-17-14-40-20
Folder Strucutre

Syntax:

{{title | uppercase}} 

Step 2: app.component.ts in app module

import { Component } from '@angular/core';
import { RouterOutlet } from '@angular/router';
import { CommonModule } from '@angular/common';

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [RouterOutlet,CommonModule],
  templateUrl: './app.component.html',
  styleUrl: './app.component.css'
})
export class AppComponent {
  title = 'pipe';
}

LowerCase

Example: To demonstrate creating the built-in LowerCase pipe in Angular 17.

<!--app.component.html-->
<h1>Lowercase Pipe</h1>  
<b>{{title | lowercase}}</b><br/>  
<b>{{"HELLO GEEKS"| lowercase}}</b><br/>  

Output:

Screenshot-(305)
Lowercase pipe

Uppercase

Example: To demonstrate creating the built-in UpperCase pipe in Angular 17.

<!--app.component.html-->
<h1>Uppercase Pipe</h1>  
<b>{{title | uppercase}}</b><br/>  
<b>{{"Hello Geeks"| uppercase}}</b><br/>  

Output:

Screenshot-(304)
uppercase

JSONpipe

app.component.ts in add json data

import { Component } from '@angular/core';
import { RouterOutlet } from '@angular/router';
import { CommonModule } from '@angular/common';

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [RouterOutlet,CommonModule],
  templateUrl: './app.component.html',
  styleUrl: './app.component.css'
})
export class AppComponent {
  title = 'pipe';
  mydata = {name: 'geek', age: '25', address:{a1: 'Paris', a2: 'France'}};  
}

Example: To demonstrate creating the built-in JSON pipe in Angular 17.

<!--app.component.html-->
<h1>Json Pipe</h1>
<b>{{mydata | json}}</b>

Output:

Screenshot-(306)
json pipe

Datepipe

Example: To demonstrate creating datepipe.

//app.component.ts
import { Component } from '@angular/core';
import { RouterOutlet } from '@angular/router';
import { CommonModule } from '@angular/common';

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [RouterOutlet,CommonModule],
  templateUrl: './app.component.html',
  styleUrl: './app.component.css'
})
export class AppComponent {
  title = 'pipe';
  todaydate = new Date();  
 
}

Example: To demonstrate creating the built-in Data pipe in Angular 17.

<!--app.component.html-->
<h1>Date pipe</h1>
<b>{{todaydate | date:'d/M/y'}}</b><br />
<b>{{todaydate | date:'shortTime'}}</b>

Output:

Screenshot-(307)

Currencypipe

Example: To demonstrate creating the built-in Currency pipe in Angular 17.

<!--app.component.html-->
<h1>currency Pipe</h1>
<h3>{{1220 | currency :'INR'}}</h3>
<h3>{{12200| currency :'USD'}}</h3>
<h3>{{12200| currency :'GBP'}}</h3>

Output:

Screenshot-(308)
currency pipe

Percentpipe

Example: To demonstrate creating the built-in Percent pipe in Angular 17.

<!--app.component.html-->
<h1>Percent Pipe</h1>  
<b>{{00.84565 | percent}}</b>  

Output:

Screenshot-(309)

Slicepipe

// app.component.ts
JavaScriptimport { Component } from '@angular/core';
import { RouterOutlet } from '@angular/router';
import { CommonModule } from '@angular/common';

@Component({
    selector: 'app-root',
    standalone: true,
    imports: [RouterOutlet, CommonModule],
    templateUrl: './app.component.html',
    styleUrl: './app.component.css'
})
export class AppComponent {
    title = 'pipe';
    months = ['Jan', 'Feb', 'Mar', 'April', 'May', 'Jun',
        'July', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec'];

}

Example: To demonstrate creating the built-in Slice pipe in Angular 17.

<!--app.component.html-->
<h1>Slice Pipe</h1>  
<b>{{months | slice:3:9}}</b>  

Output:

Screenshot-(310)
slice pipe

Decimalpipe

Example: To demonstrate creating the built-in Decimal pipe in Angular 17.

<!--app.component.html-->
<h1>Decimal Pipe</h1>  
<b>{{ 454.78787814 | number: '3.4-4' }}</b>

Output:

Screenshot-(320)
decimal pipe

Next Article

Similar Reads

three90RightbarBannerImg