Bird
0
0

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:
  1. Step 1: Recall Angular pipe class requirements

    A custom pipe class must implement the PipeTransform interface and define a transform method.
  2. 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.
  3. Final Answer:

    export class MyPipe implements PipeTransform { transform(value: any): any { return value; } } -> Option A
  4. 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

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes