Skip to content

Instantly share code, notes, and snippets.

@gildniy
Created December 12, 2017 02:56
Show Gist options
  • Save gildniy/e846f399c1ac9db5bfa7e3b90da8a746 to your computer and use it in GitHub Desktop.
Save gildniy/e846f399c1ac9db5bfa7e3b90da8a746 to your computer and use it in GitHub Desktop.
Capitalize pipe
import { Pipe, PipeTransform } from '@angular/core';
/*
* Capitalize the first letter of the string
* Takes a string as a value.
* Usage:
* value | capitalize
* Example:
* // value.name = daniel
* {{ value.name | capitalize }}
* fromats to: Daniel
*/
@Pipe({
name: 'capitalize'
})
export class CapitalizePipe 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