Last active
August 29, 2015 14:15
-
-
Save ryepup/81e7a0e75820e100e1fb to your computer and use it in GitHub Desktop.
DOM macro directive
This file contains 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.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