Want to capitalize the first letter of string in AngularJS? Use this capitalize filter from AngularJS core:
1 2 3 4 5 6 7 8 9 10 11 12 |
var app = angular.module('app', []); app.controller('Ctrl', function ($scope) { $scope.msg = 'hello, world.'; }); app.filter('capitalize', function() { return function(input) { return (angular.isString(input) && input.length > 0) ? input.charAt(0).toUpperCase() + input.substr(1).toLowerCase() : input; } }); |
1 2 3 4 5 6 |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app="app"> <div ng-controller="Ctrl"> <p><b>My Text:</b> {{msg | capitalize}}</p> </div> </div> |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.