Skip to content

Instantly share code, notes, and snippets.

@snapjay
Created August 21, 2014 18:22
Show Gist options
  • Save snapjay/5f659bb1b491c8fb2441 to your computer and use it in GitHub Desktop.
Save snapjay/5f659bb1b491c8fb2441 to your computer and use it in GitHub Desktop.
AngularJS directive for SVG 'use' sprite
'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);
}
};
}])
@chriskrycho
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment