Skip to content

Instantly share code, notes, and snippets.

@elgervb
Last active April 6, 2016 14:10
Show Gist options
  • Save elgervb/cede53c326306bb3a34f to your computer and use it in GitHub Desktop.
Save elgervb/cede53c326306bb3a34f to your computer and use it in GitHub Desktop.
ng-script
/**
* 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