Search code examples
angularcapitalize

Capitalize first letter of a string using Angular or typescript


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


Solution

  • 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}}