AngularJS - IE8 HTML模板模板、AngularJS、HTML

2023-09-14 00:20:45 作者:輕舞飛揚

有谁知道在IE8使用AngularJS一个样板模板。在文档中有一整个章节专门讨论越来越角工作与IE8,似乎所需的步骤是相当具体,但到目前为止,我曾与像命令收效甚微NG-包括

Does anyone know of a boilerplate template for using AngularJS in IE8. In the docs there is a whole section devoted to getting Angular working with IE8 and it seems the steps required are quite specific, but so far I have had little success with commands like ng-include

如果该步骤是相当具体的话,我认为有人被证实与IE8合作一些样板code的地方,这将是AP preciated如果可以分享。至少,如果它不工作,那么你至少知道你已经从已知基线开始,将使其更容易找出问题。

If the steps are quite specific then I assume someone has some boilerplate code somewhere that is confirmed to work with IE8, it would be appreciated if that could be shared. At least if it does not work then you at least know you have started from known baseline and would make it easier to isolate problems.

推荐答案

我已经用在IE8上运行,只需几个JavaScript的'修复'完美的罚款AngularJS 2生产应用。

I have created 2 production applications using AngularJS that run in IE8 perfectly fine with just a few javascript 'fixes'.

首先,如果开发商控制台未打开的console.log语句将失败。我固定它具有以下JS初始页面会派生的角上的应用程序片段:

First, if the developer console is not open the console.log statements will fail. I fixed it with the following js snippet on the initial page that spawns the angular app:

 // 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中,该功能没有实现,所以我用这个片段:

Second, I use toISOString for converting date time stamps. In IE, that function is not implemented so I am using this snippet:

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

三,在foreach方法不支持IE,所以我用这个:

Third, the forEach method is not supported in IE, so I am using this:

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

所有这些code片断是从StackOverflow的答案偷猎和我,但情况因人而异。

All of these code snippets were poached from StackOverflow answers and the work for me but YMMV.

我通过角IE8文档阅读,我还没有遇到任何的文档中描述的情况。对于指令,我使用格式为:&LT; D​​IV指令-名称&gt; ,一切工作正常。

I read through the angular IE8 documentation and I have not run into any of the situations described in the documentation. For directives, I use the format: <div directive-name> and everything works fine.