AngularJS - How to Capitalize the first letter of word Using filter?

By Hardik Savani | April 13, 2016 | | 62530 Viewer | Category : jQuery AngularJS


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>



Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.