Skip to content

Instantly share code, notes, and snippets.

@guilhermehn
Last active December 16, 2015 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guilhermehn/5506304 to your computer and use it in GitHub Desktop.
Save guilhermehn/5506304 to your computer and use it in GitHub Desktop.
AngularJS directive - Uppercas
angular.module('ng', []).directive('uppercase', function(){
return {
require: 'ngModel',
link: function(scope, element, attrs, modelCtrl){
// Cria o parsers
var _uppercase = function(inputValue){
var uppercased = angular.uppercase(inputValue);
if(uppercased !== inputValue){
modelCtrl.$setViewValue(uppercased);
modelCtrl.$render();
}
return uppercased;
};
modelCtrl.$parsers.push(_uppercase);
_uppercase(scope[attrs.ngModel]);
}
};
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment