Which of the following is the correct way to define a custom pipe class in Angular?
easy📝 Syntax Q12 of 15
Angular - Pipes
Which of the following is the correct way to define a custom pipe class in Angular?
Aexport class MyPipe implements PipeTransform { transform(value: any): any { return value; } }
Bexport class MyPipe { transform(value: any): any { return value; } }
Cexport function MyPipe(value: any): any { return value; }
Dexport class MyPipe implements OnInit { transform(value: any): any { return value; } }
Step-by-Step Solution
Solution:
Step 1: Recall Angular pipe class requirements
A custom pipe class must implement the PipeTransform interface and define a transform method.
Step 2: Check each option
export class MyPipe implements PipeTransform { transform(value: any): any { return value; } } correctly implements PipeTransform and has transform method. export class MyPipe { transform(value: any): any { return value; } } misses interface. export function MyPipe(value: any): any { return value; } is a function, not a class. export class MyPipe implements OnInit { transform(value: any): any { return value; } } wrongly implements OnInit instead of PipeTransform.
Final Answer:
export class MyPipe implements PipeTransform { transform(value: any): any { return value; } } -> Option A
Quick Check:
Pipe class implements PipeTransform [OK]
Quick Trick:Custom pipes must implement PipeTransform interface [OK]
Common Mistakes:
Forgetting to implement PipeTransform
Using a function instead of a class
Implementing wrong interfaces like OnInit
Master "Pipes" in Angular
9 interactive learning modes - each teaches the same concept differently