Skip to content

Instantly share code, notes, and snippets.

@jbmoelker
Last active August 6, 2020 20:49
Show Gist options
  • Save jbmoelker/9471081 to your computer and use it in GitHub Desktop.
Save jbmoelker/9471081 to your computer and use it in GitHub Desktop.
viewBox is an AngularJS directive which adds support for using an expression for the SVG viewBox, by using `data-view-box` which sets `viewBox` attribute. Code borrowed from http://stackoverflow.com/a/14596319
angular
.module('directives.viewBox', [])
.directive('viewBox', [
/**
* @ngdoc directive
* @name directives.viewBox.directive:viewBox
* @description
* Supports using expression for SVG viewBox, by
* using `data-view-box` which sets `viewBox` attribute.
* Code borrowed from http://stackoverflow.com/a/14596319
* @element SVG
* @example
<doc:example>
<doc:source>
<svg data-view-box="{{ APP_VIEWPORT.viewBox }}"></svg>
</doc:source>
</doc:example>
*/
function () {
'use strict';
return {
link: function (scope, element, attributes) {
attributes.$observe('viewBox', function(value) {
element.attr('viewBox', value);
});
}
};
}
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment