ItSolutionStuff.com

AngularJS - How to Capitalize the First Letter of Word Example

By Hardik Savani • October 20, 2023
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: Angular
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

AngularJS Scroll to a Specific Element using Anchorscroll

Read Now →

AngularJS Convert Comma Separated String to Array Example

Read Now →

AngularJS - How to Create Read More/Less Toggle using Directive?

Read Now →

How to Call AngularJS Controller Function in JQuery?

Read Now →

How to Remove # from URL in AngularJS?

Read Now →

AngularJS Image Upload with Preview Example

Read Now →

How to Hide Div After Some Time in AngularJS?

Read Now →

AngularJS Tooltip using UI Bootstrap tpls HTML Example

Read Now →

AngularJS Sorting(using Orderby Filter) Table Data Example

Read Now →

How to Change Date Format using Date Filter in AngularJS?

Read Now →

AngularJS - How to Limit String Length using Filter?

Read Now →

How to Remove HTML Tags from String in AngularJS?

Read Now →