Created
April 10, 2013 13:47
-
-
Save matiboy/5354770 to your computer and use it in GitHub Desktop.
Angular directive for local loading of CSS file
This file contains hidden or 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
| '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