javascript AngularJS 在 IE8 中未定义

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15884699/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 02:27:07  来源:igfitidea点击:

AngularJS is undefined in IE8

javascriptinternet-explorerinternet-explorer-8angularjs

提问by joseym

I'm working on a massive application that uses AngularJs.

我正在开发一个使用 AngularJs 的大型应用程序。

When I view the page in IE8 I get super nifty console errors like Object doesn't support property or method 'module', Object doesn't support property or method 'widget', unable to get value of the property 'controller': object is null or undefined, and IE really sucks, cant you just tell them to download chrome?

当我在IE8浏览网页,我得到超级漂亮的控制台类似错误Object doesn't support property or method 'module'Object doesn't support property or method 'widget'unable to get value of the property 'controller': object is null or undefined,和IE really sucks, cant you just tell them to download chrome?

After fighting with it for a while I decided to log the typeof angular, to which the console returned undefined.

在与它斗争了一段时间后,我决定记录typeof angular控制台返回的undefined

Everything works as expected in IE9, IE10, and all browsers that don't suck.

在 IE9、IE10 和所有不烂的浏览器中,一切都按预期工作。

Please help!

请帮忙!

Edit:

编辑

It appears that angular is undefinedbefore it gets to my first controller, so I don't think it has to do with the ieshim ...

看来角度是undefined在它到达我的第一个控制器之前,所以我认为它与 ieshim 无关......

采纳答案by joseym

So this was totally my bad (or the guy that started this app months ago).

所以这完全是我的错(或者几个月前启动这个应用程序的人)。

My application controller had var angular = angular || {}at the top, IE8 didn't agree with this declaration.

我的应用程序控制器var angular = angular || {}在顶部,IE8 不同意这个声明。

After removing that all is well.

删除后一切正常。

回答by koolunix

I've been working with IE8 for six months now, feel your pain.

我已经使用 IE8 六个月了,感受一下你的痛苦。

Without seeing your code it's hard exactly to say what's wrong

如果没有看到您的代码,很难准确说出问题所在

Here's a very very basic page I just tested with IE8, for you to compare against:

这是我刚刚用 IE8 测试过的一个非常非常基本的页面,供您比较:

<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=8">
    <meta charset="utf-8">
    <title>Prompt Detail View</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <!-- disable browser cache -->
    <meta http-equiv="cache-control" content="max-age=0" />
    <meta http-equiv="cache-control" content="no-cache" />
    <meta http-equiv="expires" content="0" />
    <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
    <meta http-equiv="pragma" content="no-cache" />


    <!--[if lte IE 8]>
    <script>
        document.createElement('ng-include');
        document.createElement('ng-pluralize');
        document.createElement('ng-view');
        // Optionally these for CSS
        document.createElement('ng:include');
        document.createElement('ng:pluralize');
        document.createElement('ng:view');
    </script>
    <![endif]-->

    <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
          <script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->

    <script src="js/jquery-1.7.2.min.js"></script>
    <script src="js/angular-1.0.2.js" ng:autobind></script>


<script>
var pageModule = angular.module('pageModule',[])
.controller('pageCtrl',function($scope) {
   $scope.foo = 'my foo'; 
});

</script>
</head>


<body>
    <div ng-app="pageModule"
        ng-controller="pageCtrl">
            {{foo}}
    </div>
</body>
</html>

回答by JoeG

I also had the same issue, my IE9 browser didn't recognize any AngularJs tag, after trying everything I decided to run the html file in a server and it worked.

我也遇到了同样的问题,我的 IE9 浏览器无法识别任何 AngularJs 标签,在尝试了一切之后我决定在服务器中运行 html 文件并且它工作正常。

To summerize, when I executed the file as follows it didn't work

总结一下,当我按如下方式执行文件时,它不起作用

file:///C:/AngularJS/firstTest.html

file:///C:/AngularJS/firstTest.html

when I executed the file in the server as follows it did work

当我按如下方式在服务器中执行文件时,它确实有效

http://localhost:7001/AngularJS/firstTest.html

http://localhost:7001/AngularJS/firstTest.html

回答by Shantha Moorthy K

var versionError = angular.module('versionErrors', [])
  .controller('versionCtrl', function($scope) {
    $scope.name = 'Shantha Moorthy K';
  });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular.min.js"></script>
<!DOCTYPE html>
<html lang="en">

<head>
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  <meta charset="utf-8">
  <title>AngularJS with Lower version Error's</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>


<body>
  <div ng-app="versionErrors" ng-controller="versionCtrl">
    {{name}}
  </div>
</body>

</html>

Object doesn't support property or method 'module'

对象不支持属性或方法“模块”

`If you are using AngularJS + Lower version of IE(8), Please include the content="IE=edge".

`如果您使用的是 AngularJS + 较低版本的 IE(8),请包含 content="IE=edge"。

After include that you will overcome the below error's.

包含之后,您将克服以下错误。

  1. Object expected
  2. Object doesn't support property or method 'module'` ##
  1. 预期对象
  2. 对象不支持属性或方法 'module'` ##