Bird
0
0

What is wrong with this pipe definition?

medium📝 Debug Q7 of 15
Angular - Pipes
What is wrong with this pipe definition?
@Pipe({name: 'double'})
export class DoublePipe implements PipeTransform {
  transform(value: number): number {
    value * 2;
  }
}
AIncorrect pipe name format
Btransform method should accept string, not number
CMissing return statement in transform method
DPipe class should not implement PipeTransform
Step-by-Step Solution
Solution:
  1. Step 1: Review transform method code

    The method multiplies value by 2 but does not return the result.
  2. Step 2: Identify missing return

    Without return, the pipe returns undefined, causing incorrect output.
  3. Final Answer:

    Missing return statement in transform method -> Option C
  4. Quick Check:

    transform must return the transformed value [OK]
Quick Trick: Always return value from transform() [OK]
Common Mistakes:
  • Forgetting return keyword
  • Wrong parameter types
  • Misnaming pipe

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes