使用Angular应用程序的IE8中的“TypeError:Object不支持此操作未定义”错误

时间:2013-08-23 20:36:01

标签: javascript internet-explorer angularjs

“TypeError:Object不支持此actionundefined”当我尝试执行我的角度应用程序时,这就是IE8控制台中的消息。 Angular并没有执行它应该执行的任何操作。有人会提示解决这个问题吗?我已经包含了json2和ui-ieshiv。我也用这种方式写了html标签:

<html xmlns:ng="http://angularjs.org" class="ng-app:app" ng-app="app" id="ng-app">

一切顺利!

2 个答案:

答案 0 :(得分:9)

当我在其中运行角度应用程序时,IE8有三件事情不喜欢。

1)console.log函数。在角度引导之前,我不得不将这个javascript放在页面中:

// Avoid `console` errors in browsers that lack a console.
            (function() {
                var method;
                var noop = function () {};
                var methods = [
                    'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',
                    'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log',
                    'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',
                    'timeStamp', 'trace', 'warn'
                ];
                var length = methods.length;
                var console = (window.console = window.console || {});

                while (length--) {
                    method = methods[length];

                    // Only stub undefined methods.
                    if (!console[method]) {
                        console[method] = noop;
                    }
                }
            }());

2)toISOString函数

 /*IE8 toISOString hack */
            if (!Date.prototype.toISOString) {
                Date.prototype.toISOString = function() {
                    function pad(n) { return n < 10 ? '0' + n : n }
                    return this.getUTCFullYear() + '-'
                        + pad(this.getUTCMonth() + 1) + '-'
                        + pad(this.getUTCDate()) + 'T'
                        + pad(this.getUTCHours()) + ':'
                        + pad(this.getUTCMinutes()) + ':'
                        + pad(this.getUTCSeconds()) + '.'
                        + pad(this.getUTCMilliseconds()) + 'Z';
                };
            }

3)forEach功能

  /*IE8 hack to support forEach */
            if (!Array.prototype.forEach) {
              Array.prototype.forEach = function(fn, scope) {
                for(var i = 0, len = this.length; i < len; ++i) {
                  fn.call(scope, this[i], i, this);
                }
              }
            }

请注意,我自己并没有写任何这些内容。我已经从SO开始了。

这些是为了在IE8中运行而必须修复的罪魁祸首。现在,它运作正常。

答案 1 :(得分:0)

问题解决了! 我在IE8和插件Angular-Restful之间发现了一个问题。当我拿走它时,我的应用程序又回来了。