Capitalize The First Letter of String Using AngularJs

AngularJS provides an uppercase filter out of the box which can capitalize all letters of a string. But, it doesn’t have a built-in solution to capitalize just the first letter of the string.

However, you can easily fix this issue by using the following custom filter.

var app = angular.module('app', []);

app.filter('ucfirst', function() {
    return function(text) {
      return (!!text) ? text.charAt(0).toUpperCase() + text.substr(1).toLowerCase() : '';
    }
});

Usage:

<p>{{ randomText | ucfirst }}</p>

Read Also: Using Custom Filter to Reverse a Input String in AngularJS

0 Comments

Leave a Comment.