将Handsontable添加到Angular-CLI脚本时会覆盖ZoneAwarePromise

时间:2017-06-15 11:57:45

标签: javascript angular angular-cli handsontable zone.js

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

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

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

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)

显然,(默认导入polyfills.ts)在Handsontable之前加载(实际上是polyfills bundle is loaded first)。通过将JS文件复制到我的资产文件夹并将Handsontable导入移动到index.html,我找到了一种可行的解决方法:

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

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

高度赞赏任何有关如何解决此问题的想法。

2 个答案:

答案 0 :(得分:1)

我有同样的问题,我已将“import'zone.js / dist / zone'”从“polyfill.ts”移到“main.ts”

答案 1 :(得分:0)

请更新到zone.js的最新版本,错误就会消失。