SlideShare a Scribd company logo
MASTERING
ANGULAR
PIPES
Nir Kaufman
Nir Kaufman
Head of Angular Development @ 500Tech
- AngularJS evangelist
- International speaker
- Guitar player
Angular Pipes Workshop
Angular Pipes Workshop
Angular Pipes Workshop
PART 1
WHAT ARE PIPES?
Reusable
display-value
transformations
Take in input data
and transform it to a
desired output
Used in templates
@Component({ 

template: `

<h1>{{ title | uppercase }}</h1>

`,

})



export class Examples {

private title:string;



constructor() {

this.title = "Pipes Examples";

}

}
PART 2
BUILT-IN PIPES
Angular ships with
some core pipes
@Component({

selector: 'examples',

template: `

<h1>{{ title | uppercase }}</h1>

<h1>{{ object | json }}</h1>

<h1>{{ today | date }}</h1>

<h1>{{ data | async }}</h1>

`,

})



export class Examples {



constructor() {

this.title = "Pipes Examples";

this.object = { id: 1, name: 'nir' };

this.today = new Date();



this.data = new Promise<string>( resolve => {

setTimeout( () => resolve(“data from server"), 3000 )

})

}

}
Angular Pipes Workshop
Pipes can accept
arguments
import {Component} from "@angular/core";



@Component({

selector: 'examples',

template: ` 

<h1>{{ today | date:’fullDate' }}</h1>

`,

})



export class Examples {



private today:Date;



constructor() {

this.today = new Date();

}

}
Pipes can be chained
import {Component} from "@angular/core";



@Component({

selector: 'examples',

template: ` 

<h1>{{ today | date:'fullDate' | uppercase }}</h1>

`,

})



export class Examples {



private today:Date;



constructor() {

this.today = new Date();

}

}
PART 3
CUSTOM PIPES
Pipe is a Class that
implements the
PipeTransform
interface
import {PipeTransform} from "@angular/core";





export class Capitalize implements PipeTransform {



transform(value:string):string {

let first = value.substr(0, 1).toUpperCase();

let rest = value.substring(1).toLowerCase();

return first + rest;

}

}
We use the Pipe
decorator to declare its
name
import {Pipe, PipeTransform} from "@angular/core";



@Pipe({

name: 'capitalize'

})



export class Capitalize implements PipeTransform {



transform(value:string):string {

let first = value.substr(0, 1).toUpperCase();

let rest = value.substring(1).toLowerCase();

return first + rest;

}

}
To use the pipe we
must declare it
@Component({

selector: 'examples',

pipes: [ Capitalize ],

template: ` 

<h1>{{ firstName | capitalize }}</h1> 

`,

})
Besides the value we
can accept any number
of arguments
@Pipe({

name: 'truncate'

})



export class TruncatePipe implements PipeTransform {



transform(value:string, args:string[]):string {



let limit = args.length > 0 ?

parseInt(args[0], 10) : 10;



let trail = args.length > 1 ?

args[1] : '...';



return value.length > limit ?

value.substring(0, limit) + trail : value;

}

}
@Component({

selector: 'examples',

pipes: [ TruncatePipe ],

template: ` 

<h1>{{ firstName | truncate : 4 : '___' }}</h1>
`,

})
Pipes are pure by
default. The pipe
executes only if the
value has changed
@Pipe({

name: 'capitalize',

pure: true

})
Impure pipes run each
time change detection
occurs
PART 4
HANDS ON!
HOW IT WORKS?
- Choose a pipe to work on
- Mark it in this work sheet: 

http://tinyurl.com/ztjtd25
- Build your pipe on a separate branch
- Create pull request when done
GET INSPIRED
- https://github.com/a8m/angular-filter
- https://github.com/jprichardson/string.js
- https://github.com/dleitee/strman
WHO WILL
BE THE
PIPE MASTER?
THANK YOU!
nir@500tech.com
@nirkaufman
il.linkedin.com/in/nirkaufman
github.com/nirkaufman
ANGULARJS IL
meetup.com/Angular-AfterHours/
meetup.com/AngularJS-IL
Nir Kaufman
meetup.com/frontend-band/

More Related Content

PDF
Angular Directives
ODP
Routing & Navigating Pages in Angular 2
PDF
Angular Dependency Injection
PPTX
Angular 2.0 Pipes
PDF
Angular - Chapter 4 - Data and Event Handling
PDF
Angular directives and pipes
PDF
Angular - Chapter 7 - HTTP Services
PDF
Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...
Angular Directives
Routing & Navigating Pages in Angular 2
Angular Dependency Injection
Angular 2.0 Pipes
Angular - Chapter 4 - Data and Event Handling
Angular directives and pipes
Angular - Chapter 7 - HTTP Services
Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...

What's hot (20)

PDF
Angular data binding
PDF
Workshop 4: NodeJS. Express Framework & MongoDB.
PDF
Angular
PPTX
Angular Data Binding
PPTX
Angular modules in depth
PDF
RxJS & Angular Reactive Forms @ Codemotion 2019
PPT
Java script final presentation
PPTX
Angular 2.0 forms
PPTX
Node.js Express
PPTX
Introduction to angular with a simple but complete project
PPTX
Sharing Data Between Angular Components
PDF
Angular - Chapter 3 - Components
PPTX
Introduction to Angularjs
PPT
Introduction to Javascript
PPTX
PPTX
Java 8 presentation
PPTX
Angular Data Binding
PDF
Angular Observables & RxJS Introduction
PPTX
Spring Boot and REST API
PPTX
Angular 14.pptx
Angular data binding
Workshop 4: NodeJS. Express Framework & MongoDB.
Angular
Angular Data Binding
Angular modules in depth
RxJS & Angular Reactive Forms @ Codemotion 2019
Java script final presentation
Angular 2.0 forms
Node.js Express
Introduction to angular with a simple but complete project
Sharing Data Between Angular Components
Angular - Chapter 3 - Components
Introduction to Angularjs
Introduction to Javascript
Java 8 presentation
Angular Data Binding
Angular Observables & RxJS Introduction
Spring Boot and REST API
Angular 14.pptx
Ad

Viewers also liked (20)

PDF
Redux with angular 2 - workshop 2016
PDF
How Angular2 Can Improve Your AngularJS Apps Today!
PDF
Angular2 workshop
PDF
Angular2 - getting-ready
PDF
Data Structures in javaScript 2015
PDF
redux and angular - up and running
PDF
Up & running with ECMAScript6
PDF
Solid angular
PDF
Angularjs - Unit testing introduction
PDF
Webstorm
PDF
Angular 2 - Core Concepts
PDF
Angularjs - lazy loading techniques
PDF
Building Universal Applications with Angular 2
PPTX
PHP Introduction
PDF
Server side development using Swift and Vapor
PDF
Webpack and angularjs
PDF
AngularJS - Services
PDF
Angular js - 10 reasons to choose angularjs
PDF
Angular redux
PDF
Angular (v2 and up) - Morning to understand - Linagora
Redux with angular 2 - workshop 2016
How Angular2 Can Improve Your AngularJS Apps Today!
Angular2 workshop
Angular2 - getting-ready
Data Structures in javaScript 2015
redux and angular - up and running
Up & running with ECMAScript6
Solid angular
Angularjs - Unit testing introduction
Webstorm
Angular 2 - Core Concepts
Angularjs - lazy loading techniques
Building Universal Applications with Angular 2
PHP Introduction
Server side development using Swift and Vapor
Webpack and angularjs
AngularJS - Services
Angular js - 10 reasons to choose angularjs
Angular redux
Angular (v2 and up) - Morning to understand - Linagora
Ad

More from Nir Kaufman (12)

PDF
Angular Prestige: Less-known API and techniques
PDF
Angular CLI custom builders
PDF
Electronic music 101 for developers
PDF
Nestjs MasterClass Slides
PDF
Redux pattens - JSHeroes 2018
PDF
Angular EE - Special Workshop by Nir Kaufman
PDF
Boosting Angular runtime performance
PDF
Decorators in js
PDF
Styling recipes for Angular components
PDF
Introduction To Angular's reactive forms
PDF
AngularJS performance & production tips
PDF
Angular js routing options
Angular Prestige: Less-known API and techniques
Angular CLI custom builders
Electronic music 101 for developers
Nestjs MasterClass Slides
Redux pattens - JSHeroes 2018
Angular EE - Special Workshop by Nir Kaufman
Boosting Angular runtime performance
Decorators in js
Styling recipes for Angular components
Introduction To Angular's reactive forms
AngularJS performance & production tips
Angular js routing options

Recently uploaded (20)

PDF
Enable Enterprise-Ready Security on IBM i Systems.pdf
PDF
Reimagining Insurance: Connected Data for Confident Decisions.pdf
PPTX
CroxyProxy Instagram Access id login.pptx
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PDF
CIFDAQ's Token Spotlight: SKY - A Forgotten Giant's Comeback?
PDF
agentic-ai-and-the-future-of-autonomous-systems.pdf
PDF
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Why Endpoint Security Is Critical in a Remote Work Era?
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
PDF
REPORT: Heating appliances market in Poland 2024
PDF
DevOps & Developer Experience Summer BBQ
PDF
Software Development Methodologies in 2025
PDF
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
PDF
CIFDAQ's Teaching Thursday: Moving Averages Made Simple
PDF
Google’s NotebookLM Unveils Video Overviews
PDF
Smarter Business Operations Powered by IoT Remote Monitoring
Enable Enterprise-Ready Security on IBM i Systems.pdf
Reimagining Insurance: Connected Data for Confident Decisions.pdf
CroxyProxy Instagram Access id login.pptx
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
CIFDAQ's Token Spotlight: SKY - A Forgotten Giant's Comeback?
agentic-ai-and-the-future-of-autonomous-systems.pdf
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Why Endpoint Security Is Critical in a Remote Work Era?
NewMind AI Monthly Chronicles - July 2025
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
REPORT: Heating appliances market in Poland 2024
DevOps & Developer Experience Summer BBQ
Software Development Methodologies in 2025
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
CIFDAQ's Teaching Thursday: Moving Averages Made Simple
Google’s NotebookLM Unveils Video Overviews
Smarter Business Operations Powered by IoT Remote Monitoring

Angular Pipes Workshop