问题描述
我正在用angular8构建一个应用程序.我从事angular5/6/7的工作,对于那些应用程序,我没有评论polyfills.ts中存在的导入.对于角度8,它只有3个导入,即classlist.js,web-animation-js和zone.js/dist/zone.我的应用程序在IE中工作正常.但是我开始使用include函数来查看某项是否存在.它在chrome中可以正常工作.在IE中,它抛出Object不支持属性或方法"includes"的错误.
I am building an application in angular8. I worked on angular5/6/7 and for those applications, I uncommented the imports that exist in the polyfills.ts. For angular 8, it has only 3 imports i.e classlist.js, web-animation-js and zone.js/dist/zone. My application is working fine in IE. But I started using the includes function to see if an item exists. It works fine in chrome. In IE it throws Object doesn't support property or method 'includes' error.
推荐答案
includes
是 Array.prototype
和 String.prototype
,并且IE不支持.您需要使用如下所示的polyfill:
includes
is a function that exist on Array.prototype
and String.prototype
and it is not supported on IE. You need to use a polyfill like the following:
if (!String.prototype.includes) {
String.prototype.includes = function(search, start) {
'use strict';
if (typeof start !== 'number') {
start = 0;
}
if (start + search.length > this.length) {
return false;
} else {
return this.indexOf(search, start) !== -1;
}
};
}
或类似的数组.您还可以检查 Core.js 中的填充
Or similar for Arrays. You can also check Core.js for polyfills
这篇关于角度8:对象不支持属性或方法“包含"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!