Created
June 15, 2015 20:21
-
-
Save smorcuend/09c68b53cc618f02e70d to your computer and use it in GitHub Desktop.
md-svg-icon angular directive for material angular
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
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