私は AngularJS を使用して 2 つの実稼働アプリケーションを作成しました。これらは 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>
。すべて正常に動作します。