Skip to content

Instantly share code, notes, and snippets.

@mmmeff
Created January 27, 2015 02:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmmeff/b3f9797d5aa67ba8e906 to your computer and use it in GitHub Desktop.
Save mmmeff/b3f9797d5aa67ba8e906 to your computer and use it in GitHub Desktop.
Quick little SVG injector in Angular. Uses Snap-svg, so make sure it's included in your project.
var app = angular.module('myApp');
app.factory('Snap', [
function () {
return window.Snap;
}
]);
app.directive('ngSvg', function (Snap) {
"use strict";
return {
replace: true,
controller: function ($scope) {
Snap.load($scope.src, function (f) {
$scope.el.append(f);
});
},
scope: {
src: '@'
},
link: function (scope, el, attrs) {
scope.el = Snap(el[0]);
},
template: '<svg height="100%" width="100%"></svg>'
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment