Created
September 20, 2014 12:07
-
-
Save toboqus/f39d436505192f740119 to your computer and use it in GitHub Desktop.
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
myApp.directive('capitalizeFirst', function($parse) { | |
return { | |
require: 'ngModel', | |
link: function(scope, element, attrs, modelCtrl) { | |
var capitalize = function(inputValue) { | |
if (inputValue === undefined) { inputValue = ''; } | |
var capitalized = inputValue.charAt(0).toUpperCase() + | |
inputValue.substring(1); | |
if(capitalized !== inputValue) { | |
modelCtrl.$setViewValue(capitalized); | |
modelCtrl.$render(); | |
} | |
return capitalized; | |
} | |
modelCtrl.$parsers.push(capitalize); | |
capitalize($parse(attrs.ngModel)(scope)); // capitalize initial value | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment