【发布时间】:2017-02-21 08:16:06
【问题描述】:
如何在 Angular 2 cli 项目中添加 polyfill 的代码?
例如,我想使用来自Mozilla MDN 的以下polyfill:
if (!Array.prototype.includes) {
Object.defineProperty(Array.prototype, 'includes', {
value: function(searchElement, fromIndex) {
if (this == null) { throw new TypeError('"this" is null or not defined'); }
var o = Object(this);
var len = o.length >>> 0;
if (len === 0) { return false; }
var n = fromIndex | 0;
var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
while (k < len) {
if (o[k] === searchElement) { return true; }
k++;
}
return false;
}
});
}
我发现另一个线程通过 npm (How to add Web Animations API polyfill to an Angular 2 project created with Angular CLI ) 安装了 polyfill。但是如果没有 npm 包怎么办呢?
【问题讨论】:
-
是你项目的 core-js 的一部分吗?