InterviewHubPRO
Section Overview
Q31

Question 31 of 283

Part 1: Architecture, Components, Directives & Lifecycle (1 - 35)

11%
Angular & Signals (283 Qs)•Part 1: Architecture, Components, Directives & Lifecycle (1 - 35)

What is a custom pipe?

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

  1. A pipe is a class decorated with pipe metadata @Pipe decorator, which you import from the core Angular library For example,
javascript
     @Pipe({name: 'myCustomPipe'})
  1. 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,
javascript
 interface PipeTransform {
   transform(value: any, ...args: any[]): any
 }
  1. The @Pipe decorator allows you to define the pipe name that you'll use within template expressions. It must be a valid JavaScript identifier.
javascript
 template: `{{someInputValue | myCustomPipe: someOtherValue}}`