Angular 角度8+IE 11:缺少一些多边形填充

Angular 角度8+IE 11:缺少一些多边形填充,angular,internet-explorer-11,Angular,Internet Explorer 11,我们需要让Angular 8和IE 11一起工作 我们使用target=es5,ng serve创建pollyfills-es5.js,其中包含所需的数组includes polyfill,但控制台中存在错误:error TypeError:Object不支持属性或方法“includes”。其他代码工作正常,一些组件显示在屏幕上 tsconfig.json { ... "compilerOptions": { ... "target": "es2015", "li

我们需要让Angular 8和IE 11一起工作

我们使用target=es5,ng serve创建pollyfills-es5.js,其中包含所需的数组includes polyfill,但控制台中存在错误:error TypeError:Object不支持属性或方法“includes”。其他代码工作正常,一些组件显示在屏幕上

tsconfig.json

{
  ...
  "compilerOptions": {
    ...
    "target": "es2015",
    "lib": ["es2018", "dom"],
    "module": "esnext"
  }
}
tsconfig.es5.json

{
  "extends": "./src/tsconfig.app.json",
  "compilerOptions": {
    "target": "es5"
  }
}
angular.json

...
"build":{
    ...
   "configurations":{ 
         "es5": {
              "tsConfig": "./tsconfig.es5.json"
            }
    }
    ...
},
"serve":{
    ...
   "configurations":{ 
         "es5": {
              "browserTarget": "frontend:build:es5"
            }
    }
    ...
}
浏览器列表:上一个chrome版本,即11

要启动代码,我们使用:ng serve-live reload=false-configuration=es5

在resulted index.html中,我们有


但在控制台中,我们有:ERROR-TypeError:Object不支持属性或方法“includes”

angular cli只将所需的IE11 polyfills添加到polyfills-es5中。因此,在这个文件中,您将只找到多边形填充以进行角度工作。Angular在其源代码中不使用Array.includes,因此,如果希望将其包含在polyfill中,则必须将其添加到自己的polyfill.ts文件中

import 'core-js/modules/es.array.includes'

这将在polyfills.js中结束,而不是polyfills-es5.js。您可以找到更多信息

angular cli仅将所需的IE11 polyfills添加到polyfills-es5中。因此,在这个文件中,您将只找到多边形填充以进行角度工作。Angular在其源代码中不使用Array.includes,因此,如果希望将其包含在polyfill中,则必须将其添加到自己的polyfill.ts文件中

import 'core-js/modules/es.array.includes'

这将在polyfills.js中结束,而不是polyfills-es5.js。您可以找到更多信息

为我添加polyfill.ts中在Angular 10中工作的下一行

import 'core-js/es7/array';

对于我来说,在polyfill.ts中添加以下行在Angular 10中起作用

import 'core-js/es7/array';