`function loadScript() { var script = document.createElement(‘script’), head = document.getElementsByTagName(‘head’)\[0\]; script.type = ‘text/javascript’; script.charset = ‘UTF-8’; script.src = urls\[num\]; if (script.addEventListener) { script.addEventListener(‘load’, function () { num = num+1; if(num < urls.length) { loadScript(); }else if(num == urls.length){ jQuery(document).ready(function($) { $(‘#multiselect’).multiselect(); }); } }, false); } else if (script.attachEvent) { script.attachEvent(‘onreadystatechange’, function () { var target = window.event.srcElement; if (target.readyState == ‘loaded’) { num = num+1; if(num < urls.length) { loadScript(); } }else if(num == urls.length){ jQuery(document).ready(function($) { $(‘#multiselect’).multiselect(); }); } }); } head.appendChild(script); } function loadJsWithCommon(){ loadScript(); } function loadCommon(jsPath){ urls.push(jsPath); loadScript(); waitLoad(); waitLoadsetInterval(); sessionStorage.setItem(“loaded”,””); console.log(“implement finally”); document.addEventListener(“DOMContentLoaded”, function(event) { console.log(“DOM fully loaded and parsed”); console.log(“1 Determine if there is a loaded loaded”+sessionStorage.getItem(“loaded”)); }); }
var waitLoad = function(){ if(num < urls.length){ setTimeout(“waitLoad()”, 300) } }
function waitLoadsetInterval(){ var timer= window.setInterval(function () { console.log(“waitLoadsetInterval”); if(num >= urls.length){ console.log(“js loading finished”); window.clearInterval(timer); angular.element(document).ready(function() { console.log(“2 Determine if there is a loaded loaded”+sessionStorage.getItem(“loaded”)); if(!sessionStorage.getItem(“loaded”)){ console.log(“get the name of the ng-app”+document.getElementsByTagName(“body”)\[0\].attributes\[“ng-app”\].value); angular.bootstrap(document.getElementsByTagName(“body”)\[0\], \[document.getElementsByTagName(“body”)\[0\].attributes\[“ng-app”\].value\]); } }); } }, 1000); }`
The problem is <body ng-app=”” in the js asynchronous loading is not completed on the start so can not find the module so we listen to the js load and then to determine once there is the implementation of the past we do not have to execute no script in the start once