【问题标题】:Zone.js has detected that ZoneAwarePromise `(window|global).Promise` has been overwritten in Angular 8Zone.js 检测到 ZoneAwarePromise `(window|global).Promise` 已在 Angular 8 中被覆盖
【发布时间】:2020-03-07 03:28:11
【问题描述】:

大家好,以前我使用 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"
  },

在我突然出错后我安装了与我的项目相关的所有依赖项,我从互联网上研究了许多资源后,我不知道发生了哪个依赖项问题或任何其他问题,我在项目中实施了所有解决方案,但没有去ZoneAwarePromise 错误

我找到了这个解决方案,即{ ngZone: 'noop'},它是 ma​​in.ts 文件

ma​​in.ts

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

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

所以请帮我找出问题出在哪里,我正在使用 Angular 8Typescript 版本 ~3.4.3

【问题讨论】:

  • 尝试删除node_modules 并制作npm install。在npm update之后尝试相同的操作
  • 做同样的错误
  • zone.js 对你来说似乎是个问题。也许你使用的 nodejs/npm 版本有问题
  • 不知道是什么问题

标签: typescript angular8


【解决方案1】:

我遇到了同样的问题,我在这里找到了解决方案: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. 对不起我的英语不好。

【讨论】:

    猜你喜欢
    • 2017-08-02
    • 1970-01-01
    • 1970-01-01
    • 2017-02-14
    • 2017-11-17
    • 2018-11-04
    • 1970-01-01
    • 2021-12-15
    • 2017-10-10
    相关资源
    最近更新 更多