Last active
April 6, 2016 14:10
-
-
Save elgervb/cede53c326306bb3a34f to your computer and use it in GitHub Desktop.
ng-script
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
/** | |
* add a script dynamically to the head of your document | |
* use <script ng-src="/path/to/script.js"></script> | |
*/ | |
.directive('script', ($parse, $rootScope) => { | |
return { | |
restrict: 'E', | |
terminal: true, | |
link: (scope, element, attr) => { | |
if (attr.ngSrc) { | |
let script = document.createElement('script'); | |
script.setAttribute('src', attr.ngSrc); | |
script.setAttribute('defer', 'defere'); | |
script.setAttribute('async', 'asunc'); | |
document.head.appendChild(script); | |
} | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment