Created
January 27, 2015 02:14
-
-
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.
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 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