Custom Pipe

Your own template formatter, written as a class with a `transform` method.

What is Custom Pipe?

A custom pipe is your own template formatter. Write a class with a transform method and the @Pipe decorator.

@Pipe({ name: 'minutes' })
export class MinutesPipe implements PipeTransform {
  transform(total: number) {
    return `${Math.floor(total / 60)}h ${total % 60}m`;
  }
}

// {{ 135 | minutes }}  ->  2h 15m

Level: Journeyman · More Angular terms at this level

Updated