简体   繁体   English

将AngularJS 1.4.7注入IE交叉延伸器扩展

[英]Injecting AngularJS 1.4.7 into an IE crossrider extension

I am developing an extension for browsers using the Crossrider framework. 我正在使用Crossrider框架为浏览器开发扩展。 I am using the line 我正在使用这条线

appAPI.resources.includeJS('js/angular.min.js');

to inject angular.js into the extension. 将angular.js注入扩展名。 This works fine on Chrome, but on IE 11 I get the error 这在Chrome上工作正常,但在IE 11上我收到错误

---- JS Exception from: IE test staging ----
Error: Object expected
Source: Microsoft JScript runtime error
Location: resources
Line: 131

I looked around and found a few answers that suggested that either jQuery might be missing or there might be a trailing comma in the code itself. 我环顾四周,发现了一些答案,表明jQuery可能会丢失,或者代码本身可能有一个尾随逗号。 However, I am using 但是,我正在使用

var jq = document.createElement('script');
jq.src = "http://code.jquery.com/jquery-1.11.3.js";
document.getElementsByTagName('body')[0].appendChild(jq);

to inject jquery into the document, so that shouldn't be a problem. 将jquery注入到文档中,这应该不是问题。 As for the possibility of there being a trailing comma in the JS, I changed from the minified to the unminified version of AngularJS, but still got the same error, which makes me think that the line number in the error is meaningless. 至于JS中有一个尾随逗号的可能性,我从AngularJS的缩小版本变为非透明版本,但仍然得到了同样的错误,这让我觉得错误中的行号没有意义。 If that's the care, or forget that, no matter what the case is. 如果这是关心,或忘记,无论是什么情况。 Could someone please tell me what's going on and how to fix it? 有人可以告诉我发生了什么以及如何解决它?

PS. PS。 My environment is Windows 7 Ultimate 32 bit on VMWare Workstation 12 on a Ubuntu 14.04 LTS x64 bit machine 我的环境是在Ubuntu 14.04 LTS x64位计算机上的VMWare Workstation 12上的Windows 7 Ultimate 32位

I think you have a mixed scopes issue here. 我认为你这里有混合范围问题。 appAPI.resources.includeJS runs in the Extension Page scope which the jq element you ate adding runs in the HTML Page scope. appAPI.resources.includeJS在扩展页范围内运行,您添加的jq元素在HTML页范围中运行。 If you want to add the AngularJS to the HTML Page scope, use appAPI.resources.addInlineJS as follows: 如果要将AngularJS添加到HTML页面范围,请使用appAPI.resources.addInlineJS ,如下所示:

var jq = document.createElement('script');
jq.src = "https://http://code.jquery.com/jquery-1.11.3.js";
document.getElementsByTagName('body')[0].appendChild(jq);
appAPI.resources.addInlineJS('js/angular.min.js');

[ Disclosure: I am a Crossrider employee] [ 披露:我是Crossrider员工]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM