Forked from subudeepak/angular-loadscript-with-documentwrite.js
Last active
August 29, 2015 14:21
-
-
Save butaixianran/812feaf2cacdb704930a to your computer and use it in GitHub Desktop.
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
/** | |
* 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