Created
August 21, 2014 18:22
-
-
Save snapjay/5f659bb1b491c8fb2441 to your computer and use it in GitHub Desktop.
AngularJS directive for SVG 'use' sprite
This file contains hidden or 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
'use strict'; | |
angular.module('ngSvg', []) | |
.directive('usesvg', [function(){ | |
return { | |
restrict : 'E', | |
replace: true, | |
controller : ['$scope', function($scope){ | |
}], | |
scope: { | |
useid:'@' | |
}, | |
template: '<svg><use xlink:href=""/> </svg>', | |
link:function(scope, svg, attrs){ | |
svg.attr('viewBox', document.getElementById(attrs.useid).getAttribute('viewBox')); | |
svg.children().attr('xlink:href', '#' + attrs.useid); | |
} | |
}; | |
}]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This looks like it will solve a problem I've just run into (and this is my first outing with Angular). Do you have an example of it in use? That would be superb.