Skip to content

Instantly share code, notes, and snippets.

@EnriqueV
Created June 26, 2018 16:53
Show Gist options
  • Save EnriqueV/0fdca44109170afe35777d2449796604 to your computer and use it in GitHub Desktop.
Save EnriqueV/0fdca44109170afe35777d2449796604 to your computer and use it in GitHub Desktop.
app.directive("limitTo", [function() {
return {
restrict: "A",
link: function(scope, elem, attrs) {
var limit = parseInt(attrs.limitTo);
angular.element(elem).on("keydown", function(e) {
if (this.value.length == limit) e.preventDefault();
});
}
}
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment