MyInternships.in

Directives, Pipes & Templates

Angular Custom Pipes

A custom pipe is a class with a @Pipe decorator implementing PipeTransform. The transform method receives the value plus any parameters and returns the transformed result.


What is Custom Pipes in Angular?

A custom pipe is a class with a @Pipe decorator implementing PipeTransform. The transform method receives the value plus any parameters and returns the transformed result.

Custom Pipes example

A stipend formatting pipe
TypeScript
import { Pipe, PipeTransform } from '@angular/core';

@Pipe({ name: 'stipend', standalone: true })
export class StipendPipe implements PipeTransform {
  transform(value: number | null, unpaidLabel = 'Unpaid'): string {
    if (!value) return unpaidLabel;
    return `₹${value.toLocaleString('en-IN')}/month`;
  }
}

Using it

HTML
{{ job.stipend | stipend }}
{{ job.stipend | stipend:'Not disclosed' }}

Key points to remember

  • Pipes are pure by default — they re-run only when the input reference changes.
  • Set pure: false only when you must react to internal mutations, and expect a performance cost.
  • Keep transform side-effect free; it runs during change detection.

Common mistakes with Custom Pipes

  • Marking a pipe impure to make it "work", which then runs on every cycle.
  • Performing HTTP calls inside a pipe.

Angular Custom Pipes— Interview Questions & FAQs

What is the difference between a pure and an impure pipe?+

A pure pipe re-runs only when its input reference changes, which is efficient. An impure pipe runs on every change detection cycle, so it can detect mutations but costs far more.

Related Angular Topics

Keep learning with these closely related lessons.

Ready to use your Angular skills?

Find verified Angular internships and fresher developer jobs across India.

Browse Angular Internships