Bird
0
0

What will be the output of this pipe usage?

medium📝 component behavior Q5 of 15
Angular - Pipes
What will be the output of this pipe usage?
@Pipe({name: 'exclaim'})
export class ExclaimPipe implements PipeTransform {
  transform(value: string, times: number = 1): string {
    return value + '!'.repeat(times);
  }
}

Template: {{ 'Hi' | exclaim:3 }}
AHi!
BHi!!!
CHi3!
DError
Step-by-Step Solution
Solution:
  1. Step 1: Understand the transform method parameters

    The pipe adds exclamation marks repeated 'times' times to the string.
  2. Step 2: Apply the pipe with times=3

    'Hi' + '!' repeated 3 times = 'Hi!!!'.
  3. Final Answer:

    Hi!!! -> Option B
  4. Quick Check:

    Exclaim pipe output = Hi!!! [OK]
Quick Trick: Pipe parameters customize output easily [OK]
Common Mistakes:
  • Ignoring the parameter and outputting one !
  • Appending the number instead of repeating !
  • Expecting error due to parameter

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes