Skip to content

Instantly share code, notes, and snippets.

@groner
Created November 4, 2010 15:59
Show Gist options
  • Save groner/662694 to your computer and use it in GitHub Desktop.
Save groner/662694 to your computer and use it in GitHub Desktop.
angular x:clearable directive to place a clear button at the end of an input
angular.directive('x:clearable', function(expression, element) {
var compiler = this;
compiler.directives(true);
compiler.descend(true);
element.css({'padding-right': '2em'});
element.after('<button style="margin-left: -2em; border: none; background-color: transparent;">&#x2612;</button>');
return function(element) {
var scope = this;
var button = element.next('button');
button.bind('click', function() {
scope.$set(element.attr('name'), '');
scope.$root.$eval();
});
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment