javascript AngularJS IE 8 支持
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20240896/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
AngularJS IE 8 Support
提问by jonny bordo
I'm building a one-page website, using AngularJS, ui-router and jquery, and I need it to support ie 8 browsers.
I followed the instructions from the AngularJS documentation (link), and I also read thisand followed its instructions.
In a nutshell: I added this code in the header:
我正在构建一个单页网站,使用 AngularJS、ui-router 和 jquery,我需要它来支持 ie 8 浏览器。
我遵循了 AngularJS 文档(链接)中的说明,我也阅读了这篇文章并遵循了它的说明。
简而言之:我在标题中添加了以下代码:
<html xmlns:ng="http://angularjs.org" id="ng-app" ng-app="myApp">
and also:
并且:
<!--[if lt IE 9]>
<script type="text/javascript" src="/app/js/3rdparty/html5shiv.js"></script>
<script type="text/javascript" src="/app/js/3rdparty/json3.min.js"></script>
<![endif]-->
All of my directives are restricted to be used as attribute directives (no custom tags).
But still, no view is being rendered, and no directive is working (on ie8).
我所有的指令都被限制用作属性指令(没有自定义标签)。
但是仍然没有视图被渲染,也没有指令在工作(在 ie8 上)。
I started using ui-router only recently, and the problem existed even before.
I really can't find the problem, and I've searched a lot.
There are many duplicates for this, I know, but none of their solutions helped me (and most of them pretty much refer to angularjs's documentation).
I haven't posted any other code, since there's a lot of it, and I really can't figure out what part of the code (other than the index.html) can be causing any problem.
I'll post any other code if you think it might help.
I'm really lost and would really be grateful if someone could guide me to a solution.
Thank you very much
我最近才开始使用ui-router,之前就存在这个问题。
实在找不到问题所在,找了很多。
我知道这有很多重复项,但他们的解决方案都没有帮助我(而且其中大多数几乎都参考了 angularjs 的文档)。
我没有发布任何其他代码,因为有很多代码,而且我真的无法弄清楚代码的哪一部分(index.html 除外)会导致任何问题。
如果您认为它可能有帮助,我会发布任何其他代码。
我真的很迷茫,如果有人能指导我找到解决方案,我将不胜感激。
非常感谢你
采纳答案by jonny bordo
Seems I made a bit of a fool out of myself.
The problem was that I was using some reserved words, and apparently IE8 really doesn't like it at all.
For instance I had a parameter named "class" on an object, so using obj.class
just made IE8 freak out.
The same with a function named "delete" (again inside an object, so I was using functionHoldingObject.delete
.
看来我把自己弄得有点傻了。
问题是我使用了一些保留字,显然 IE8 真的不喜欢它。
例如,我在一个对象上有一个名为“class”的参数,所以使用obj.class
刚刚让 IE8 吓坏了。
与名为“delete”的函数相同(再次在对象内部,所以我使用functionHoldingObject.delete
.
I knew about reserved words, I just didn't think using them as a parameter of an object is harmful.
In order to fix this, I just changed the names for some, and used obj["reservedWord"]
for others, both solutions work on all browsers.
我知道保留字,我只是不认为将它们用作对象的参数是有害的。为了解决这个问题,我只是更改了一些名称,并用于obj["reservedWord"]
其他解决方案,这两种解决方案都适用于所有浏览器。
Another error I found, was that I was using the Array.prototype.indexOf
function without knowing that IE8 doesn't support it. So I just added an implementation (which is very easy).
You could get help on that on the MDNsite.
我发现的另一个错误是我在使用该Array.prototype.indexOf
功能时不知道 IE8 不支持它。所以我只是添加了一个实现(这很容易)。
你可以在MDN站点上获得帮助。
回答by Senthil
In case if you've used any console.log()
within your controller or service or factory then IE-8 won't load the angular at all. It's weird.
如果您console.log()
在控制器或服务或工厂中使用过任何内容,则 IE-8 将根本不会加载角度。有点奇怪。
回答by benek
I have met the same problem recently because of the compatibility mode.
由于兼容模式,我最近遇到了同样的问题。
Try to force it with :
尝试强制它:
<!--[if IE 8]><!--> <meta http-equiv="X-UA-Compatible" content="IE=8" /> <!--<![endif]-->
Also check in your IE8 browser that your compatibility mode is not IE7.
还要检查您的 IE8 浏览器,确认您的兼容模式不是 IE7。