Custom pipes

Pipes are similar to filters in Angular 1, which take an input and transform the data before displaying it within the template. There are some sets of predefined pipes available, which we can directly use in our template files, such as date and currency. Other than this, we can also create custom pipes according to our requirements. In our application we are implementing an Ordinalpipe, which takes a number as input and accordingly outputs its ordinal number; for 1 the output will be 1st:

// src/filters/ordinal.ts import { Pipe, PipeTransform } from '@angular/core'; @Pipe({name: 'ordinal'}) export class OrdinalPipe implements PipeTransform {   transform(value: number, args: string[]): any {     if (!value) return value;  if(isNaN(value) ...

Get Hybrid Mobile Development with Ionic now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.