簡體   English   中英

IE11中的Angular 4錯誤

[英]Angular 4 error in IE11

我有一個在Chrome上成功運行的Angular 4項目。 但是它沒有在IE11上加載polyfills.bundle.js中的以下錯誤(我使用命令“ng build --env = prod”來構建站點):

var exports = module.exports = function (iterable, entries, fn, that, ITERATOR) {
  var iterFn = ITERATOR ? function () { return iterable; } : getIterFn(iterable);
  var f = ctx(fn, that, entries ? 2 : 1);
  var index = 0;
  var length, step, iterator, result;
  if (typeof iterFn != 'function') throw TypeError(iterable + ' is not iterable!');

iterFn在這里未定義,因此拋出錯誤。 請指教。

為了更好地支持IE11,您需要在polyfill中添加一些es6導入。 清單如下:

/** IE9, IE10 and IE11 requires all of the following polyfills. **/
import 'core-js/es6/symbol';
import 'core-js/es6/object';
import 'core-js/es6/function';
import 'core-js/es6/parse-int';
import 'core-js/es6/parse-float';
import 'core-js/es6/number';
import 'core-js/es6/math';
import 'core-js/es6/string';
import 'core-js/es6/date';
import 'core-js/es6/array';
import 'core-js/es6/regexp';
import 'core-js/es6/map';
import 'core-js/es6/weak-map';
import 'core-js/es6/set';

由於@Sumit已經回答需要在polyfill.ts文件中添加這些導入:

import 'core-js/es6/symbol';
import 'core-js/es6/object';
import 'core-js/es6/function';
import 'core-js/es6/parse-int';
import 'core-js/es6/parse-float';
import 'core-js/es6/number';
import 'core-js/es6/math';
import 'core-js/es6/string';
import 'core-js/es6/date';
import 'core-js/es6/array';
import 'core-js/es6/regexp';
import 'core-js/es6/map';
import 'core-js/es6/weak-map';
import 'core-js/es6/set';

另外你需要導入反射api:

/** IE10 and IE11 requires the following for the Reflect API. */

 import 'core-js/es6/reflect';

/** Evergreen browsers require these. **/

// Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators),you 
//can remove.

import 'core-js/es7/reflect';

此外,如果您在項目中使用Angular材質動畫,則必須導入角度材質的Web動畫才能在IE上正常運行。

import 'web-animations-js';  // Run `npm install --save web-animations-js`.

最后但並非最不重要的是一個非常重要的庫,可以在IE上正確運行你的Angular項目:

/** IE10 and IE11 requires the following for NgClass support on SVG elements */
import 'classlist.js';  // Run `npm install --save classlist.js`

我有同樣的錯誤,這個特殊錯誤需要數組類。 為了保持我的庫更小,我只是導入了數組類。 在那之后,我得到了一個不同的錯誤,它需要經常使用的字符串類,所以我首先將這兩個用於。我有點極簡主義,所以我不想把其他人帶到需要之前。

import 'core-js/es6/array';
import 'core-js/es6/string';

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM