SlideShare a Scribd company logo
Angular 2.0 Pipes
Angular 2.0 Pipes
{{ expression [| pipe_name[:parameter_value] ... ] }}
Angular 2.0 Pipes
@Pipe({name: 'exponentialStrength'})
export class ExponentialStrengthPipe implements PipeTransform {
transform(value:number, args:string[]) : any {
return Math.pow(value, parseInt(args[0] || '1', 10));
}
}
import {Component} from '@angular/core';
import {ExponentialStrengthPipe} from './exponential-strength.pipe';
@Component({
selector: 'power-booster',
template: `
<h2>Power Booster</h2>
<p>
Super power boost: {{ 2 | exponentialStrength: 10 }}
</p>
`,
pipes: [ExponentialStrengthPipe]
})
export class PowerBooster { }
// Initial view: "Message: "
// After 500ms: Message: You are my Hero!"
@Component({
selector: 'hero-message',
template: 'Message: {{ delayedMessage | async }}',
})
export class HeroAsyncMessageComponent {
delayedMessage = new Promise((resolve, reject) => {
setTimeout(() => resolve('You are my Hero!'), 500);
});
}
import {Pipe} from '@angular/core';
@Pipe({ name: 'fetch', pure: false })
export class FetchJsonPipe {
private fetchedValue:any;
private fetchPromise:Promise<any>;
transform(value:string, args:string[]):any {
if (!this.fetchPromise) {
this.fetchPromise = window.fetch(value)
.then((result:any) => result.json())
.then((json:any) => this.fetchedValue = json);
}
return this.fetchedValue;
}
}
import {FetchJsonPipe} from './fetch-json.pipe';
@Component({
selector: 'hero-list',
template: `
<h4>Heroes from JSON File</h4>
<div *ngFor="let hero of ( 'heroes.json' | fetch ) ">
{{hero.name}}
</div>
<p>Heroes as JSON:
{{ 'heroes.json' | fetch | json }}
</p>
`,
pipes: [FetchJsonPipe]
})
export class HeroListComponent {
/* I've got nothing to do ;-) */
}
Angular 2.0 Pipes

More Related Content

PDF
Angular Pipes Workshop
PPT
Java database connectivity
PDF
Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...
PDF
Angular Dependency Injection
PPTX
Angular Data Binding
PPTX
Form Validation in JavaScript
PPT
jQuery Ajax
Angular Pipes Workshop
Java database connectivity
Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...
Angular Dependency Injection
Angular Data Binding
Form Validation in JavaScript
jQuery Ajax

What's hot (20)

PPTX
Angular modules in depth
PPTX
Angular 2.0 Dependency injection
PDF
Restful Integration with WSO2 ESB
 
PDF
Angular - Chapter 7 - HTTP Services
PPTX
Express js
PPTX
Introduction to SASS
PPTX
Sequelize
PPTX
Angular 9
PPTX
React
PPT
Collections Framework
PDF
Angular Notes.pdf
PDF
ES6 presentation
PPTX
Angular Directives
PPT
Angular Introduction By Surekha Gadkari
PDF
Angular Interview Questions-PDF.pdf
PPTX
EAV Sytem- Magento EAV Model
PPTX
Spring Framework
 
PPTX
Choice router mule
PPTX
Popup boxes
PDF
JavaScript Programming
Angular modules in depth
Angular 2.0 Dependency injection
Restful Integration with WSO2 ESB
 
Angular - Chapter 7 - HTTP Services
Express js
Introduction to SASS
Sequelize
Angular 9
React
Collections Framework
Angular Notes.pdf
ES6 presentation
Angular Directives
Angular Introduction By Surekha Gadkari
Angular Interview Questions-PDF.pdf
EAV Sytem- Magento EAV Model
Spring Framework
 
Choice router mule
Popup boxes
JavaScript Programming
Ad

Viewers also liked (20)

PPTX
Http Communication in Angular 2.0
PPTX
Angular 2 Architecture (Bucharest 26/10/2016)
PPTX
Template syntax in Angular 2.0
PPTX
Angular 2.0 forms
PPTX
Angular 2.0 Routing and Navigation
PPTX
Component lifecycle hooks in Angular 2.0
PPTX
Async & Parallel in JavaScript
PPTX
Angular 2 NgModule
PPTX
Angular 1.x vs. Angular 2.x
PPTX
Performance Optimization In Angular 2
PPTX
Angular 2 Architecture
PDF
Angular 2 Routing
PPTX
Node.js File system & Streams
PPTX
Node.js Socket.IO
PPTX
Node.js Event Emitter
PPTX
Node js overview
PPTX
Angular 2.0 Views
PPTX
Modules and injector
PDF
Nodejs
PPTX
Node.js Spplication Scaling
Http Communication in Angular 2.0
Angular 2 Architecture (Bucharest 26/10/2016)
Template syntax in Angular 2.0
Angular 2.0 forms
Angular 2.0 Routing and Navigation
Component lifecycle hooks in Angular 2.0
Async & Parallel in JavaScript
Angular 2 NgModule
Angular 1.x vs. Angular 2.x
Performance Optimization In Angular 2
Angular 2 Architecture
Angular 2 Routing
Node.js File system & Streams
Node.js Socket.IO
Node.js Event Emitter
Node js overview
Angular 2.0 Views
Modules and injector
Nodejs
Node.js Spplication Scaling
Ad

Similar to Angular 2.0 Pipes (20)

PDF
Implicit parameters, when to use them (or not)!
PDF
What is new in sulu 2.0
 
PDF
What is your money doing?
PDF
Angular 2.0 - What to expect
PDF
polymorphism in c++ with Full Explanation.
PDF
Pragmatic Functional Refactoring with Java 8
PDF
Dependency Injection with Dagger 2 presentation
PDF
Object Oriented Programming (OOP) using C++ - Lecture 3
PPTX
ES6 Overview
PDF
Creating a Facebook Clone - Part XXVII - Transcript.pdf
PPTX
Final requirement (2)
PDF
Exploring Angular 2 - Episode 2
ODP
OpenStack Oslo Messaging RPC API Tutorial Demo Call, Cast and Fanout
PPTX
Functions in C++ programming language.pptx
PPTX
Function C++
PDF
Java 14
PDF
Protocol-Oriented Networking
PPTX
Classes function overloading
PPTX
Python Code Camp for Professionals 4/4
PDF
angular fundamentals.pdf angular fundamentals.pdf
Implicit parameters, when to use them (or not)!
What is new in sulu 2.0
 
What is your money doing?
Angular 2.0 - What to expect
polymorphism in c++ with Full Explanation.
Pragmatic Functional Refactoring with Java 8
Dependency Injection with Dagger 2 presentation
Object Oriented Programming (OOP) using C++ - Lecture 3
ES6 Overview
Creating a Facebook Clone - Part XXVII - Transcript.pdf
Final requirement (2)
Exploring Angular 2 - Episode 2
OpenStack Oslo Messaging RPC API Tutorial Demo Call, Cast and Fanout
Functions in C++ programming language.pptx
Function C++
Java 14
Protocol-Oriented Networking
Classes function overloading
Python Code Camp for Professionals 4/4
angular fundamentals.pdf angular fundamentals.pdf

More from Eyal Vardi (14)

PPTX
Why magic
PPTX
Smart Contract
PDF
Rachel's grandmother's recipes
PPTX
Upgrading from Angular 1.x to Angular 2.x
PPTX
Angular 2 - Ahead of-time Compilation
PPTX
Routing And Navigation
PPTX
Modules in ECMAScript 6.0
PPTX
Proxies in ECMAScript 6.0
PPTX
Iterators & Generators in ECMAScript 6.0
PPTX
Symbols in ECMAScript 6.0
PPTX
Objects & Classes in ECMAScript 6.0
PPTX
Scope & Functions in ECMAScript 6.0
PPTX
AngularJS Internal
PPTX
Node.js Express
Why magic
Smart Contract
Rachel's grandmother's recipes
Upgrading from Angular 1.x to Angular 2.x
Angular 2 - Ahead of-time Compilation
Routing And Navigation
Modules in ECMAScript 6.0
Proxies in ECMAScript 6.0
Iterators & Generators in ECMAScript 6.0
Symbols in ECMAScript 6.0
Objects & Classes in ECMAScript 6.0
Scope & Functions in ECMAScript 6.0
AngularJS Internal
Node.js Express

Recently uploaded (20)

PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
System and Network Administration Chapter 2
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
AI in Product Development-omnex systems
PDF
System and Network Administraation Chapter 3
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
Online Work Permit System for Fast Permit Processing
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PTS Company Brochure 2025 (1).pdf.......
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Internet Downloader Manager (IDM) Crack 6.42 Build 41
System and Network Administration Chapter 2
Upgrade and Innovation Strategies for SAP ERP Customers
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Navsoft: AI-Powered Business Solutions & Custom Software Development
How Creative Agencies Leverage Project Management Software.pdf
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
CHAPTER 2 - PM Management and IT Context
Design an Analysis of Algorithms I-SECS-1021-03
AI in Product Development-omnex systems
System and Network Administraation Chapter 3
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Which alternative to Crystal Reports is best for small or large businesses.pdf
Design an Analysis of Algorithms II-SECS-1021-03
Online Work Permit System for Fast Permit Processing
2025 Textile ERP Trends: SAP, Odoo & Oracle

Angular 2.0 Pipes

  • 3. {{ expression [| pipe_name[:parameter_value] ... ] }}
  • 5. @Pipe({name: 'exponentialStrength'}) export class ExponentialStrengthPipe implements PipeTransform { transform(value:number, args:string[]) : any { return Math.pow(value, parseInt(args[0] || '1', 10)); } }
  • 6. import {Component} from '@angular/core'; import {ExponentialStrengthPipe} from './exponential-strength.pipe'; @Component({ selector: 'power-booster', template: ` <h2>Power Booster</h2> <p> Super power boost: {{ 2 | exponentialStrength: 10 }} </p> `, pipes: [ExponentialStrengthPipe] }) export class PowerBooster { }
  • 7. // Initial view: "Message: " // After 500ms: Message: You are my Hero!" @Component({ selector: 'hero-message', template: 'Message: {{ delayedMessage | async }}', }) export class HeroAsyncMessageComponent { delayedMessage = new Promise((resolve, reject) => { setTimeout(() => resolve('You are my Hero!'), 500); }); }
  • 8. import {Pipe} from '@angular/core'; @Pipe({ name: 'fetch', pure: false }) export class FetchJsonPipe { private fetchedValue:any; private fetchPromise:Promise<any>; transform(value:string, args:string[]):any { if (!this.fetchPromise) { this.fetchPromise = window.fetch(value) .then((result:any) => result.json()) .then((json:any) => this.fetchedValue = json); } return this.fetchedValue; } }
  • 9. import {FetchJsonPipe} from './fetch-json.pipe'; @Component({ selector: 'hero-list', template: ` <h4>Heroes from JSON File</h4> <div *ngFor="let hero of ( 'heroes.json' | fetch ) "> {{hero.name}} </div> <p>Heroes as JSON: {{ 'heroes.json' | fetch | json }} </p> `, pipes: [FetchJsonPipe] }) export class HeroListComponent { /* I've got nothing to do ;-) */ }