Skip to content

Instantly share code, notes, and snippets.

@biborn
Forked from chl03ks/capitalizefirst.pipe.ts
Created July 25, 2017 05:53
Show Gist options
  • Select an option

  • Save biborn/dbcf5ca92d176cfecc8e4e693331bc9e to your computer and use it in GitHub Desktop.

Select an option

Save biborn/dbcf5ca92d176cfecc8e4e693331bc9e 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