Angular Hex pipe

Наступний Angular pipe форматує вхідне значення у шістнадцятковий вигляд:

hex.pipe.ts
import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
  name: 'hex',
  standalone: true,
})
export class HexPipe implements PipeTransform {

  transform(value: number): string {
    if (isNaN(value)) {
      return '';
    }
    return value.toString(16).toUpperCase();
  }

}

Приклад використання

hex_pipe_usage.html
{{ 255 | hex }} <!-- FF -->

Дивіться схожі статті за категоріями: Angular Typescript