AngularJS - How to Capitalize the First Letter of Word Example

By Hardik Savani October 20, 2023 Category : jQuery Angular

Sometimes, we want to make Capitalize string in our AngularJS project then we have to create filter because AngularJS not provide any predefined function that can Capitalize word or string.

However, you can solve this problem by makeing your own filter that can help you to make

Capitalize string or word. so let's see following example and use it.

Create Filter:

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

app.filter('capitalizeWord', function() {

return function(text) {

return (!!text) ? text.charAt(0).toUpperCase() + text.substr(1).toLowerCase() : '';

}

});

Use Filter:

<p>{{ yourWord | capitalizeWord }}</p>

I hope it can help you

Tags :
Shares