Skip to content

Instantly share code, notes, and snippets.

@ryepup
Last active August 29, 2015 14:15
Show Gist options
  • Save ryepup/81e7a0e75820e100e1fb to your computer and use it in GitHub Desktop.
Save ryepup/81e7a0e75820e100e1fb to your computer and use it in GitHub Desktop.
DOM macro directive
angular.module('my-app')
/**
* adds a glyphicon to the beginning or end of the element.
*
* usage: `<whatever my-glyphicon="heart">...</whatever>`
*
* add attribute `icon-position="after"` to put the icon at the end of
* the body.
*/
.directive('myGlyphicon', function() {
return {
// can't be used as a standalone element
restrict: 'A',
link: function(scope, element, attrs) {
// get the icon and position settings from attrs
var icon = '<span class="glyphicon glyphicon-' +
attrs.myGlyphicon +
'" aria-hidden="true"></span>';
if(attrs.iconPosition === 'after'){
element.append(icon);
}else{
element.prepend(icon);
}
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment