Zone.js检测到ZoneAwarePromise`(window | global).Promise`已在Angular 8中覆盖

时间:2019-11-11 12:32:30

标签: typescript angular8

全部,以前我使用 Angular 6 ,然后迁移到 Angular 8 ,该操作已完成,但有时会给我错误

main.js:11770 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.assertZonePatched (polyfills.js:2901)
    at new NgZone (vendor.js:80474)
    at getNgZone (vendor.js:81501)
    at PlatformRef.bootstrapModuleFactory (vendor.js:81344)
    at vendor.js:81419
    at scripts.js:22096

package.json

"dependencies": {
    "@angular/animations": "^8.0.3",
    "@angular/cdk": "^8.2.3",
    "@angular/common": "~8.0.0",
    "@angular/compiler": "~8.0.0",
    "@angular/core": "~8.0.0",
    "@angular/forms": "~8.0.0",
    "@angular/platform-browser": "~8.0.0",
    "@angular/platform-browser-dynamic": "~8.0.0",
    "@angular/router": "~8.0.0",
    "@ng-bootstrap/ng-bootstrap": "^5.1.4",
    "@ng-idle/core": "^8.0.0-beta.4",
    "@ng-idle/keepalive": "^8.0.0-beta.4",
    "@ng-select/ng-select": "^3.6.0",
    "@types/highcharts": "^7.0.0",
    "@types/jquery": "^3.3.31",
    "ag-grid-community": "^21.2.2",
    "angular-calendar": "^0.27.20",
    "angular2-draggable": "^2.3.2",
    "angular2-highcharts": "^0.5.5",
    "angular2-moment": "^1.9.0",
    "chart.js": "^2.9.2",
    "crypto-js": "^3.1.9-1",
    "date-fns": "^1.30.1",
    "exceljs": "^3.3.1",
    "export-to-csv": "^0.2.1",
    "file-saver": "^2.0.2",
    "jquery": "^3.4.1",
    "jspdf": "^1.5.3",
    "jspdf-autotable": "^3.2.10",
    "moment": "^2.24.0",
    "ng-circle-progress": "^1.5.1",
    "ng2-charts": "^2.3.0",
    "ng2-order-pipe": "^0.1.5",
    "ng2-pdf-viewer": "^6.0.2",
    "ng2-search-filter": "^0.5.1",
    "ngx-bootstrap": "^5.2.0",
    "ngx-daterangepicker-material": "^2.1.8",
    "ngx-pagination": "^4.1.0",
    "ngx-toastr": "^11.2.1",
    "ngx-tooltip": "0.0.9",
    "ngx-ui-switch": "^8.2.0",
    "number-to-words": "^1.2.4",
    "primeicons": "^2.0.0",
    "primeng": "^8.1.1",
    "quill": "^1.3.6",
    "rxjs": "~6.4.0",
    "rxjs-compat": "^6.5.3",
    "ts-xlsx": "0.0.11",
    "tslib": "^1.9.0",
    "zone.js": "~0.9.1"
  },

并且在我收到错误消息后,我安装了与项目相关的所有依赖项,突然之间我不知道我从互联网上研究了很多资源到我的项目中实现了所有解决方案,但是却没有去做之后发生了哪个依赖项问题或任何其他问题< strong> ZoneAwarePromise 错误

我找到了此解决方案,即{ ngZone: 'noop'} main.ts 文件

main.ts

platformBrowserDynamic()
  .bootstrapModule(MainModule, { ngZone: 'noop'})
  .catch(err => console.error(err));

在我将此{ ngZone: 'noop'}应用到 main.ts文件后,未显示错误,但未调用我的Project API。

因此,请帮助我解决问题出在哪里,我将 Angular 8 Typescript 版本〜3.4.3

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,并且在这里找到了解决方案:https://medium.com/angular-in-depth/do-you-still-think-that-ngzone-zone-js-is-required-for-change-detection-in-angular-16f7a575afef

  1. 导入您的组件:

    import { ApplicationRef } from '@angular/core';
    
  2. 注入:

    constructor(
     private _appService: ApplicationRef,
    ) { }
    
  3. 每次需要进行更改检测时,请执行以下操作:

    this._appService.tick();
    

这对我有用。

P。 D.对不起,我英语不好。