Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Angular Services

You're reading from   Angular Services -

Arrow left icon
Product type Paperback
Published in Feb 2017
Publisher Packt
ISBN-13 9781785882616
Length 294 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Sohail Salehi Sohail Salehi
Author Profile Icon Sohail Salehi
Sohail Salehi
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Angular Services
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
1. Setting Up the Environment FREE CHAPTER 2. Introducing Wire-Frames 3. The Collector Service - Using Controllers to Collect Data 4. The Rating Service - Data Management 5. The Notifier Service - Creating Cron Jobs in Angular 6. The Evidence Tree Builder Service - Implementing the Business Logic 7. The Report Generator Service - Creating Controllers to Set Report Template 8. The Accuracy Manager Service - Putting It All Together

Creating a custom pipe


Let's organize all custom pipes in our application in its own folder. So create a 'pipes' folder and add a new class to it as follows:

// src/app/pipes/orderby.pipe.ps 
import {Pipe, PipeTransform} from '@angular/core'; 
 
@Pipe({name: 'orderBy', pure: false}) 
export class OrderByPipe implements PipeTransform { 
  // transform is the only method in PipeTransform interface 
  transform(input: Array<any>, property: string, order: boolean):  
  // Angular invokes the `transform` method with the value of  
  // a binding as the first argument, and any parameters as the 
  // second argument in list form. 
  Array<string> { 
    input.sort((a: any, b: any) => { 
      return order  
        ? a[property] - b[property]  
        : b[property] - a[property]; 
    }); 
    return input; 
  } 
} 

The @Pipe function is the metadata that defines this class as a pipe. As you can see, we are implementing the PipeTransform interface, which has a transform() method...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at £13.99/month. Cancel anytime
Visually different images