繁体   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