Skip to content

Instantly share code, notes, and snippets.

@smorcuend
Created June 15, 2015 20:21
Show Gist options
  • Save smorcuend/09c68b53cc618f02e70d to your computer and use it in GitHub Desktop.
Save smorcuend/09c68b53cc618f02e70d to your computer and use it in GitHub Desktop.
md-svg-icon angular directive for material angular
var mdSvgIcon = angular.module('mdSvgIcon', []);
mdSvgIcon.directive('mdSvgIcon', function() {
return {
name: 'md-svg-icon',
template: '<svg class="icon" role="img" title="{{title}}"><use xlink:href="{{iconSprite}}"/></svg>',
restrict: 'E',
scope: {},
link: function preLink($scope, $element, $attrs) {
$scope.title = $attrs.title || $attrs.iconSprite;
if (!$attrs.fallbackPng || ($attrs.fallbackPng === 'false')) {
$scope.iconSprite = '#' + $attrs.iconSprite;
} else {
$element.html('<img class="icon" src="images/tools_icons/' + $scope.title + '.png" title="' + $scope.title + '"></div>');
}
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment