-3

有谁知道在 IE8 中使用 AngularJS 的样板模板。在文档中有一整节专门用于让 Angular 与 IE8 一起工作,似乎所需的步骤非常具体,但到目前为止,我在使用 ng-include 之类的命令方面收效甚微

如果这些步骤非常具体,那么我假设有人在某处有一些样板代码已确认可与 IE8 一起使用,如果可以共享,将不胜感激。至少如果它不起作用,那么您至少知道您已经从已知的基线开始,并且可以更容易地隔离问题。

4

2 回答 2

4

我已经创建了 2 个使用 AngularJS 的生产应用程序,它们在 IE8 中运行得非常好,只需几个 javascript '修复'。

首先,如果开发者控制台未打开,console.log 语句将失败。我在生成 Angular 应用程序的初始页面上使用以下 js 片段对其进行了修复:

 // 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;
                    }
                }
            }());

其次,我使用 toISOString 来转换日期时间戳。在 IE 中,该功能没有实现,所以我使用这个片段:

 /*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';
                };
            }

第三,IE不支持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);
                }
              }
            }

所有这些代码片段都是从 StackOverflow 的答案和我的工作中挖出来的,但 YMMV。

我通读了 Angular IE8 文档,但没有遇到文档中描述的任何情况。对于指令,我使用格式:<div directive-name>并且一切正常。

于 2013-07-30T19:24:19.260 回答
1

虽然问题应该更详细,但我可以说一下我过去在管理 IE8 代码方面所做的工作。

我不用担心样板文件和生产力下降程序,而是让 yeoman 为我处理所有这些。

http://yeoman.io/

Yeoman 是一个类似于 Rail 的 rake 的固执己见的助手,可以帮助您更快地构建应用程序。只需下载 generator-angular 和 yeoman 即可开始使用。

https://github.com/yeoman/generator-angular

如果您不想将 yeoman 集成到您的产品中,请查看 yeoman 如何放置 IE8 样板并使用测试应用程序复制它。

我希望这有帮助。

于 2013-07-30T18:59:39.763 回答