Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save butaixianran/812feaf2cacdb704930a to your computer and use it in GitHub Desktop.
Save butaixianran/812feaf2cacdb704930a to your computer and use it in GitHub Desktop.
/**
* This module is a variant which supports document.write. If you need document.write use this instead
* Author: Deepak Subramanian @subudeepak(https://github.com/subudeepak)
* Updated by: butaixianran @ https://gist.github.com/butaixianran/812feaf2cacdb704930a
* Distributed under MIT License
*/
/*global angular */
(function (ng) {
'use strict';
var app = ng.module('ngLoadScript', []);
app.directive('script', function() {
return {
restrict: 'E',
scope: false,
link: function(scope, elem, attr)
{
if (attr.type==='text/javascript-lazy')
{
var s = document.createElement("script");
s.type = "text/javascript";
var src = elem.attr('src');
if(src!==undefined)
{
s.src = src;
}
else
{
var code = elem.text();
s.text = angularCorrections(code);
}
elem.after(s);
elem.remove();
}
}
};
});
}(angular));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment