Challenge - 5 Problems
Angular Pipes Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
Output of parameterized pipe with multiple parameters
Given the Angular pipe usage below, what will be the rendered output?
Assume the
{{ 12345 | customFormat:'prefix':'suffix' }}Assume the
customFormat pipe adds the prefix and suffix strings around the number.Angular
import { Pipe, PipeTransform } from '@angular/core'; @Pipe({name: 'customFormat'}) export class CustomFormatPipe implements PipeTransform { transform(value: number, prefix: string, suffix: string): string { return `${prefix}${value}${suffix}`; } }
Attempts:
2 left
💡 Hint
Remember the pipe parameters are passed in order after the value.
✗ Incorrect
The pipe receives the value 12345 and parameters 'prefix' and 'suffix'. It returns the string with prefix + value + suffix concatenated without spaces.
📝 Syntax
intermediate1:30remaining
Correct syntax for passing multiple parameters to a pipe
Which of the following Angular template expressions correctly passes two parameters to a pipe named
examplePipe?Attempts:
2 left
💡 Hint
Angular pipes accept parameters separated by colons.
✗ Incorrect
Angular pipes accept multiple parameters separated by colons. Parentheses or brackets are not used for parameters in template expressions.
🔧 Debug
advanced2:00remaining
Why does this parameterized pipe produce unexpected output?
Consider this pipe code:
When used as
transform(value: string, prefix?: string, suffix?: string): string {
return prefix + value + suffix;
}When used as
{{ 'test' | myPipe }}, it produces unexpected output ('undefinedtestundefined'). Why?Attempts:
2 left
💡 Hint
Think about what happens when undefined is concatenated with strings.
✗ Incorrect
When no parameters are passed, `prefix` and `suffix` are `undefined`. Concatenating `undefined` with strings in JavaScript results in the string 'undefined' being concatenated, producing 'undefinedtestundefined'. This leads to unexpected output.
❓ state_output
advanced2:00remaining
Output of pipe with parameter changing dynamically
In an Angular component template:
where
If
{{ value | repeat:times }}where
value = 'ha' and times is a component property starting at 2.If
times changes to 3, what is the new output?Angular
import { Pipe, PipeTransform } from '@angular/core'; @Pipe({name: 'repeat'}) export class RepeatPipe implements PipeTransform { transform(value: string, times: number): string { return value.repeat(times); } }
Attempts:
2 left
💡 Hint
The repeat method repeats the string the given number of times without spaces.
✗ Incorrect
When times is 3, value.repeat(3) returns 'hahaha' (ha repeated 3 times).
🧠 Conceptual
expert2:30remaining
Why use parameterized pipes instead of multiple pipes?
Which is the main advantage of using a parameterized pipe over chaining multiple pipes in Angular?
Attempts:
2 left
💡 Hint
Think about template readability and maintainability.
✗ Incorrect
Parameterized pipes allow passing arguments to customize behavior inside one pipe, reducing the need to chain many pipes and making templates cleaner and easier to maintain.