Skip to content

Instantly share code, notes, and snippets.

@howieweiner
Created January 7, 2015 00:46
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 howieweiner/f9db8d386a507defad2b to your computer and use it in GitHub Desktop.
Save howieweiner/f9db8d386a507defad2b to your computer and use it in GitHub Desktop.
Angular ui-select child directive to clear (Bootstrap) input
(function () {
'use strict';
angular
.module('app.directives')
.directive('uiSelectClear', SelectClear)
;
SelectClear.$inject = ['$timeout'];
/**
* Child directive for clearing ui-select
*/
function SelectClear($timeout) {
return {
restrict: 'EA',
require: '^uiSelect',
template: '<a class="btn btn-xs pull-right" style="margin-right:10px">X</a>',
replace: true,
link: function (scope, element, attrs, $select) {
element.on('click', function (e) {
e.stopPropagation();
$timeout(function () {
$select.selected = undefined;
});
});
}
};
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment