Problem Statement
What is a pipe in Angular and when would you create a custom one?
Explanation
A pipe transforms values for display in templates (e.g., `date`, `uppercase`, `currency`). Create a custom pipe when you need reusable, pure formatting logic, like masking, unit conversions, or localized labels. Keep pipes pure for performance; use impure only when the output depends on mutable inputs.
Code Solution
SolutionRead Only
@Pipe({ name: 'titleCase' })
export class TitleCasePipe implements PipeTransform {
transform(v: string){ return v.replace(/\w\S*/g, s => s[0].toUpperCase() + s.slice(1).toLowerCase()); }
}