How do you create a custom pipe in Angular?
- Create a class with the @Pipe decorator implementing PipeTransform.
- Implement a transform() method with your logic.
Example:
@Pipe({ name: 'exclaim' })
export class ExclaimPipe implements PipeTransform {
transform(value: string): string {
return value + '!!!';
}
}
Use in template:
<p>{{ 'Hello' | exclaim }}</p> <!-- Outputs: Hello!!! -->