AngularJS - How to Capitalize the First Letter of Word Example
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
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. 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, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- AngularJS Scroll to a Specific Element using Anchorscroll
- AngularJS Convert Comma Separated String to Array Example
- AngularJS - How to Create Read More/Less Toggle using Directive?
- How to Call AngularJS Controller Function in JQuery?
- How to Remove # from URL in AngularJS?
- AngularJS Image Upload with Preview Example
- How to Hide Div After Some Time in AngularJS?
- AngularJS Tooltip using UI Bootstrap tpls HTML Example
- AngularJS Sorting(using Orderby Filter) Table Data Example
- How to Change Date Format using Date Filter in AngularJS?
- AngularJS - How to Limit String Length using Filter?
- How to Remove HTML Tags from String in AngularJS?