This is the archived documentation for Angular v6. Please visit angular.io to see documentation for the current version of Angular.

PipeTransform

To create a Pipe, you must implement this interface.

See more...

      
      interface PipeTransform {
  transform(value: any, ...args: any[]): any
}
    

Description

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.

Methods

transform(value: any, ...args: any[]): any
      
      transform(value: any, ...args: any[]): any
    

Parameters

value

Type: any.

args

Type: any[].

Returns

any

Usage notes

Example

The RepeatPipe below repeats the value as many times as indicated by the first argument:

import {Pipe, PipeTransform} from '@angular/core'; @Pipe({name: 'repeat'}) export class RepeatPipe implements PipeTransform { transform(value: any, times: number) { return value.repeat(times); } }
      
      import {Pipe, PipeTransform} from '@angular/core';

@Pipe({name: 'repeat'})
export class RepeatPipe implements PipeTransform {
  transform(value: any, times: number) {
    return value.repeat(times);
  }
}
    

Invoking {{ 'ok' | repeat:3 }} in a template produces okokok.