Created
November 4, 2010 15:59
-
-
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
This file contains hidden or 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
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;">☒</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