Loading…

How to create custom Pipes in Angular 2?

In Angular 2, you can create custom pipes. The simplest way is as follows.

import { Pipe, PipeTransform } from '@angular/core';
    @Pipe({name: 'Pipename'})
    export class Pipeclass implements PipeTransform {
    transform(parameters): returntype { }
}

In the above code,


//   Pipename' is pipe's name.
//   Pipeclass is class that is assigned to custom pipe.
//   Transform is the function that works with custom pipe.
//   Parameters are the parameters that get passed to the pipe.
//   Returntype is the return type of the custom pipe.

Suggest An Answer

No suggestions avaliable!

Latest post from Angular 2 Interview Questions

Ask Question