Created
October 29, 2016 15:13
-
-
Save kaveet/e129931f76300e3be3906660972327e0 to your computer and use it in GitHub Desktop.
AngularJS Title Case Filter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Transform a string to title case. | |
Usage: | |
{{ myString | titleCase }} | |
*/ | |
angular | |
.module('filters', []) | |
.filter('titleCase', toTitleCase); | |
function toTitleCase () { | |
return function (str) { | |
return str | |
.toLowerCase() | |
.split(' ') | |
.map(function(word) { | |
return word[0].toUpperCase() + word.substr(1); | |
}) | |
.join(' '); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment