Skip to content

Instantly share code, notes, and snippets.

@matiboy
Created April 10, 2013 13:47
Show Gist options
  • Select an option

  • Save matiboy/5354770 to your computer and use it in GitHub Desktop.

Select an option

Save matiboy/5354770 to your computer and use it in GitHub Desktop.
Angular directive for local loading of CSS file
'use strict';
angular.module('assetsApp')
.directive('localCss', function () {
return {
template: '',
restrict: 'E',
link: function (scope, element, attrs) {
var style = document.createElement('link');
style.type = 'text/css';
style.href = attrs.localCssHref;
style.rel = 'stylesheet';
scope.$on('$viewContentLoaded', function() {
document.head.appendChild(style);
});
scope.$on('$destroy', function() {
style.parentNode.removeChild(style);
});
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment