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

Share Me
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Today now in this post i would like to share with you How to Capitalize the first letter of word Using filter in AngularJS. Sometimes, we need to covert Capitalize string on our AngularJS project then we must need to create a filter because AngularJS is not provide us any predefined function that can Capitalize word or string.

However, we can solve this problem by making our own filter that will help us to make capitalize any string or word.

so let’s start and see the 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>  

Read Also : How to convert Object into Array in PHP?

Thanks for read. I hope it help you. For more you can follow us on facebook.

About code chef

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by code chef →