Angular 8:对象不支持属性或方法“包含" [英] Angular 8: Object doesn't support property or method 'includes'

查看:34
本文介绍了Angular 8:对象不支持属性或方法“包含"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 angular8 中构建一个应用程序.我在 angular5/6/7 上工作,对于那些应用程序,我取消了对 polyfills.ts 中存在的导入的注释.对于 angular 8,它只有 3 个导入,即 classlist.js、web-animation-js 和 zone.js/dist/zone.我的应用程序在 IE 中运行良好.但是我开始使用包含功能来查看项目是否存在.它在 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.prototypeString.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 是否有 polyfills

Or similar for Arrays. You can also check Core.js for polyfills

这篇关于Angular 8:对象不支持属性或方法“包含"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆