javascript - IE11 在 Angular 2(TS) 中发布 Angular CLI 项目,polyfills 不工作

标签 javascript angular typescript angular-cli es5-shim

我正在使用 anugular-cli 1.0.0-beta.16,它有 polyfills.ts,看起来像这样:

// This file includes polyfills needed by Angular 2 and is loaded before
// the app. You can add your own extra polyfills to this file.
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/set';
import 'core-js/es6/reflect';

import 'core-js/es7/reflect';
import 'zone.js/dist/zone';

但是这个 pollyfills 文件在 IE11 上不工作,它在 Chrome、Firefox、EDGE 上工作,我的 main.ts 看起来像这样:

import "./polyfills.ts";
import {platformBrowserDynamic} from "@angular/platform-browser-dynamic";
import {enableProdMode} from "@angular/core";
import {environment} from "./environments/environment";
import {AppModule} from "./app/";

if (environment.production) {
  enableProdMode();
}

platformBrowserDynamic().bootstrapModule(AppModule);

在 IE11 上运行它会产生显示粗箭头表达式错误的错误

SCRIPT1002: Syntax error

对于这个位置的minifiedjs:

function arrayUnion(arr1, arr2) {
    return arr1
        .concat(arr2.filter(v => arr1.indexOf(v) === -1));
}

这就是我的 tsconfig.json 的样子

    {
  "compilerOptions": {
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": ["es6", "dom"],
    "mapRoot": "./",
    "module": "es6",
    "moduleResolution": "node",
    "outDir": "../dist/out-tsc",
    "sourceMap": true,
    "target": "es5",
    "typeRoots": [
      "../node_modules/@types"
    ]
  }
}

@Cleton 这就是我的 tsconfig 的样子

最佳答案

您可能以 es6 为目标,它将箭头函数编译为箭头函数:

let fn = () => console.log("hey");

编译为:

let fn = () => console.log("hey");

但是如果你以 es5 为目标,它会编译为:

var fn = function () { return console.log("hey"); };

似乎 IE11(或任何其他版本的资源管理器)do not yet support arrow functions .
如果你想支持它,你必须以 es5 或更低版本为目标,因为箭头函数没有 pollyfil。

关于javascript - IE11 在 Angular 2(TS) 中发布 Angular CLI 项目,polyfills 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40912921/

相关文章:

angular - 一行和一列的唯一单选按钮

javascript - 为什么 styled-components 将我的属性添加到 DOM 中?

typescript - 使用 Aurelia 的 Fetch Client 时 Azure Translator API(认知服务)上出现 CORS 错误

javascript - Yodlee Interactive - 用于身份验证的 coblogin API - 错误代码 415

javascript - jquery 在同一 DOM 中的文本之前插入

javascript - 如何通过Angular2中的链接发送基于视频上传的放置请求

angular - 为什么我无法获得体形 Angular

json - typescript JSON字符串类

javascript - 如何在 Typed JS 中永久隐藏光标

javascript - 字母数字、空格和符号的正则表达式,与我需要的不匹配