0 votes
in Angular by

What is a custom pipe?

1 Answer

0 votes
by

Apart from built-in pipes, you can write your own custom pipe with the below key characteristics:

A pipe is a class decorated with pipe metadata @Pipe decorator, which you import from the core Angular library For example,

    @Pipe({name: 'myCustomPipe'})

The pipe class implements the PipeTransform interface's transform method that accepts an input value followed by optional parameters and returns the transformed value. The structure of PipeTransform would be as below,

interface PipeTransform {

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

}

The @Pipe decorator allows you to define the pipe name that you'll use within template expressions. It must be a valid JavaScript identifier.

template: `{{someInputValue | myCustomPipe: someOtherValue}}`

...