Capitalize first letter of a string using Angular or typescript

user2004 picture user2004 · Mar 15, 2018 · Viewed 57.5k times · Source

How can I capitalize the first letter of a string using Angular or typescript?

Answer

Yerkon picture Yerkon · Mar 15, 2018
function titleCaseWord(word: string) {
  if (!word) return word;
  return word[0].toUpperCase() + word.substr(1).toLowerCase();
}

You can also use in template TitleCasePipe

Some component template:

{{value |titlecase}}