本文介绍了将 Handsontable 添加到 Angular-CLI 脚本时会覆盖 ZoneAwarePromise的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将 Handsontable 库添加到我的 Angular 项目中.使用 angular-cli,我添加了.angular-cli.json 的脚本部分:

I'd like to add the Handsontable library to my Angular project. Using angular-cli, I added Handsontable to the scripts section of .angular-cli.json:

"scripts": [
  "../node_modules/handsontable-pro/dist/handsontable.full.js"
]

Webpack 编译成功,但是在加载 Web 应用程序时,我遇到以下错误:

Webpack compiles successfully, however when loading the web application, I'm encountering the following error:

VM473:34309 Unhandled promise rejection Error: Zone.js has detected that ZoneAwarePromise `(window|global).Promise` has been overwritten.
Most likely cause is that a Promise polyfill has been loaded after Zone.js (Polyfilling Promise api is not necessary when zone.js is loaded. If you must load one, do so before loading zone.js.)
    at Function.webpackJsonp.../../../../zone.js/dist/zone.js.Zone.assertZonePatched (zone.js:44)
    at new NgZone (core.es5.js:3757)
    at PlatformRef_.webpackJsonp.../../../core/@angular/core.es5.js.PlatformRef_._bootstrapModuleFactoryWithZone (core.es5.js:4551)
    at core.es5.js:4596
    at run (eval at webpackJsonp.../../../../script-loader/addScript.js.module.exports (addScript.js:9), <anonymous>:34279:22)
    at eval (eval at webpackJsonp.../../../../script-loader/addScript.js.module.exports (addScript.js:9), <anonymous>:34292:28)
    at MutationObserver.flush (eval at webpackJsonp.../../../../script-loader/addScript.js.module.exports (addScript.js:9), <anonymous>:91358:9)
    at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:391)
    at Zone.webpackJsonp.../../../../zone.js/dist/zone.js.Zone.runGuarded (zone.js:154)
    at MutationObserver.<anonymous> (zone.js:132)

显然,zone.js(默认在 polyfills.ts 中导入)在 Handsontable 之前加载(实际上是 polyfills bundle 首先加载).我通过将 JS 文件复制到我的资产文件夹并将 Handsontable 导入移动到 index.html 找到了一个可能的解决方法:

Apparently, zone.js (imported in polyfills.ts by default) is loaded before Handsontable (actually the polyfills bundle is loaded first). I found a possible workaround by copying the JS file to my asset folder and moving the Handsontable import to the index.html:

<html>
  <head>
    <script src="assets/handsontable.full.js"></script>
  </head>
// ...

然而,这确实感觉像是一个黑客,因为 .angular-cli.json 中有一个脚本部分用于使用它.

However, this does feel like a hack, as there is a scripts section in .angular-cli.json for the purpose of using it.

非常感谢有关如何解决此问题的任何想法.

Any idea on how to fix this issue is highly appreciated.

推荐答案

我遇到了同样的问题,我将import 'zone.js/dist/zone'"从polyfill.ts"移到了main.ts"

I had same issue, i've moved "import 'zone.js/dist/zone'" from "polyfill.ts" into "main.ts"

这篇关于将 Handsontable 添加到 Angular-CLI 脚本时会覆盖 ZoneAwarePromise的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 10:57