【问题标题】:Angular2: Object doesn't support this action in Microsoft Edge browserAngular2:对象在 Microsoft Edge 浏览器中不支持此操作
【发布时间】:2020-02-03 20:46:49
【问题描述】:

我的 angular2 应用程序仅在 Microsoft Edge 中抛出异常声明 对象不支持此操作。请查看下图:

我调试并发现异常是在 promise then code 时抛出的。更具体地说,我在下面的代码中收到错误:

this.dataLayerService
            .postLogin(this.model, this.postURL)
            .then(usermasterResponse => this.setToken(usermasterResponse))
            .catch(error => {
                  this.toastCommunicationService.setMessage(error, "",
                    this.toastCommunicationService.errorType)
            });

我也在 index.html 文件中添加了下面的脚本,但也是徒劳的。

<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.34.1/es6-shim.js"></script>

任何帮助将不胜感激。

【问题讨论】:

标签: javascript angular promise microsoft-edge angular-promise


【解决方案1】:

&lt;meta http-equiv="x-ua-compatible" content="ie=edge"&gt; 放入您的 index.html 还要检查你的 polyfills 脚本并导入所有 core-js/es6/ 脚本

【讨论】:

  • 找不到 polyfill.ts 文件,您能帮帮我吗?
  • 你是如何开始你的应用程序的?使用 Angular 启动项目?
  • 无论如何你的 src 文件夹下应该有 main.ts 和 polyfills.ts
  • 是的,我已经把它放在了文件夹中,但仍然遇到同样的问题
  • 调试时发现 this.router.navigate 抛出异常。还是没搞清楚问题
【解决方案2】:

在您的 Angular 项目文件夹中找到您的 polyfills.ts 文件并导入以下行:

/** IE9, IE10 and IE11 requires all of the following polyfills. **/
import 'core-js/es6/symbol';
import 'core-js/es6/object';
import 'core-js/es7/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/es7/array';

如果您使用的是网络动画,那么您需要这个:

/** IE10 and IE11 requires the following to support `@angular/animation`. */
import 'web-animations-js';  // Run `npm install --save web-animations-js`.

对于常青浏览器,您需要这个:

/** Evergreen browsers require these. **/
import 'core-js/es6/reflect';
import 'core-js/es7/reflect';

Evergreen 浏览器定义 (original):

最新版本的 Chrome、Firefox、Internet Explorer 和 Safari 是常青浏览器,即它们会在不提示用户的情况下自动自动更新。对于 Internet Explorer,大多数人认为这意味着 IE10+。

【讨论】:

  • 找不到 polyfill.ts 文件,您能帮帮我吗?
【解决方案3】:

问题在于以下代码中的 EventSource

this.eventsource = new EventSource(this.configService.get("BaseURL"));

我通过添加 Event Source Polyfill js 解决了这个问题。我按照这个EventSource Polyfill链接安装了js。

感谢大家的帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-01-02
    • 1970-01-01
    • 2017-07-23
    • 1970-01-01
    • 2016-09-22
    • 2018-06-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多