老是报Uncaught Error: [$injector:modulerr]错误解决思路

`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("最后执行"); document.addEventListener("DOMContentLoaded", function(event) { console.log("DOM fully loaded and parsed"); console.log("1是否有加载了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加载完成"); window.clearInterval(timer); angular.element(document).ready(function() { console.log("2是否有加载了loaded判断"+sessionStorage.getItem("loaded")); if(!sessionStorage.getItem("loaded")){ console.log("获取的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); }`

问题是<body ng-app="" 在js异步加载没完成就启动了 所以找不到模块 所以我们监听js加载完再去判断一次 有执行过我们就不用执行 没脚本在启动一次 ------类似天龙八部里面的珍珑棋局逻辑……

转载于:https://my.oschina.net/u/1052192/blog/1827330

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值