Skip to content

Instantly share code, notes, and snippets.

@ryepup
Last active August 29, 2015 14:15
Show Gist options
  • Save ryepup/dcfaa1242163e108596c to your computer and use it in GitHub Desktop.
Save ryepup/dcfaa1242163e108596c to your computer and use it in GitHub Desktop.
meta directive
angular.module('my-app')
/**
* consistent UI for remove buttons
*/
.directive('myRemoveButton', function($compile) {
'use strict';
return {
restrict: 'A',
priority: 1000, // process this directive first
terminal: true, // stop compiling other directives on the
// element, we'll fix it in `post`
compile: function(element, attrs) {
// prevent recursion
element.removeAttr('my-remove-button');
element.removeAttr('data-my-remove-button');
// add other directives
element.attr('my-glyphicon', 'remove');
// make some normal changes to the element
element.addClass('btn btn-danger');
return {
post: function(scope, element, attrs, ctrl) {
// process the directives we added
$compile(element)(scope);
}
};
}
};
})
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment