Skip to content

Instantly share code, notes, and snippets.

@asmaemk
Forked from chl03ks/capitalizefirst.pipe.ts
Created August 7, 2021 15:20
Show Gist options
  • Select an option

  • Save asmaemk/e141afa174e82a0c6f520ca69417ffa3 to your computer and use it in GitHub Desktop.

Select an option

Save asmaemk/e141afa174e82a0c6f520ca69417ffa3 to your computer and use it in GitHub Desktop.
An Angular 2 pipe to capitalize the first letter of a string value.
import { Pipe, PipeTransform } from '@angular/core';
/*
* Capitalize the first letter of the string
* Takes a string as a value.
* Usage:
* value | capitalizefirst
* Example:
* // value.name = daniel
* {{ value.name | capitalizefirst }}
* fromats to: Daniel
*/
@Pipe({
name: 'capitalizeFirst'
})
export class CapitalizeFirstPipe implements PipeTransform {
transform(value: string, args: any[]): string {
if (value === null) return 'Not assigned';
return value.charAt(0).toUpperCase() + value.slice(1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment