zone.js:25 Uncaught Error: Zone already loaded

时间:2016-10-20 19:26:24

标签: angular zone

my angular application loads on click of a button. When the button is clicked secound time, it give me Zone already loaded error because zone.js content is loaded when angular2 is loaded first time.

How I will check the zone is already loaded and then can preventing to try to load it if its available?

When I delete (answered below) zone by delete window['zone'] and try to reload it again its showing zone.js:984 Uncaught ReferenceError: Zone is not defined

1 个答案:

答案 0 :(得分:0)

你可以试试这样的......

$(function (){
		function removejscssfile(filename, filetype){
		   var targetelement=(filetype=="js")? "script" : (filetype=="css")? "link" : "none" //determine element type to create nodelist from
		   var targetattr=(filetype=="js")? "src" : (filetype=="css")? "href" : "none" //determine corresponding attribute to test for
		   var allsuspects=document.getElementsByTagName(targetelement)
		   for (var i=allsuspects.length; i>=0; i--){ //search backwards within nodelist for matching elements to remove
		   if (allsuspects[i] && allsuspects[i].getAttribute(targetattr)!=null && allsuspects[i].getAttribute(targetattr).indexOf(filename)!=-1)
		       allsuspects[i].parentNode.removeChild(allsuspects[i]) //remove element by calling parentNode.removeChild()
		   }
		}
	var jsCustomerTag = $("head").children("#jsShimTag");
    if (jsCustomerTag.length == 0) {
    	jsCustomerTag = document.createElement('script');
    	jsCustomerTag.setAttribute("type", "text/javascript");
    	jsCustomerTag.setAttribute("src", " <your js file> ");
    	jsCustomerTag.id = "jsShimTag";
        document.getElementsByTagName("head")[0].appendChild(jsCustomerTag);
    }

   jsCustomerTag = null;
});