如何在 Angular 6 中将 ag-grid 从版本 18.1.0 更新到 20.1.0?

How to update ag-grid from version 18.1.0 to 20.1.0 in Angular 6?

package.json

{
  "name": "trackerui",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build --bh /trackerui/",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^6.0.2",
    "@angular/cdk": "^6.3.2",
    "@angular/common": "^6.0.2",
    "@angular/compiler": "^6.0.2",
    "@angular/core": "^6.0.2",
    "@angular/forms": "^6.0.2",
    "@angular/http": "^6.0.2",
    "@angular/material": "^6.3.2",
    "@angular/router": "^6.0.2",
    "ag-grid": "^18.1.2",
    "ag-grid-community": "^20.1.0",
    "ag-grid-enterprise": "^20.1.0",
    "angular-calendar": "^0.26.4",
    "angular-tree-component": "^7.2.1",
    "bootstrap": "^3.3.7",
    "core-js": "^2.5.4",
    "date-fns": "^1.30.1",
    "file-saver": "1.3.8",
    "jquery": "^3.3.1",
    "jquery-ui": "^1.12.1",
    "ng2-file-upload": "^1.3.0",
    "npm": "^6.3.0",
    "rxjs": "^6.0.0",
    "rxjs-compat": "^6.3.3",
    "to": "^0.2.9",
    "update": "^0.7.4",
    "xlsx": "0.12.13",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.6.3",
    "@angular/cli": "~6.0.3",
    "@angular/compiler-cli": "^6.0.2",
    "@angular/language-service": "^6.0.2",
    "@types/jasmine": "~2.8.6",
    "@types/jasminewd2": "~2.0.3",
    "@types/jquery": "^3.2.5",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.2.1",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~1.7.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~1.4.2",
    "karma-jasmine": "~1.1.1",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.3.0",
    "ts-node": "~5.0.1",
    "tslint": "~5.9.1",
    "typescript": "~2.7.2"
  }
}

我在 运行 使用 ng serve

的应用程序时遇到以下错误
  • ERROR in node_modules/ag-grid-community/dist/lib/gridOptionsWrapper.d.ts(133,52): error TS1005: ',' expected.
  • node_modules/ag-grid-community/dist/lib/gridOptionsWrapper.d.ts(133,73): error TS1144: '{' or ';' expected.
  • node_modules/ag-grid-community/dist/lib/gridOptionsWrapper.d.ts(133,101): error TS1005: ';' expected.
  • node_modules/ag-grid-community/dist/lib/gridOptionsWrapper.d.ts(133,103): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected.

我认为您还需要将 "ag-grid": "^18.1.2", 升级到 "ag-grid-angular": "^20.1.0", 才能这样做,您需要进行以下更改

第一步:转到package.json修改"ag-grid": "^18.1.2","ag-grid-angular": "20.1.0",

第 2 步: 将您的打字稿版本 "typescript": "~2.7.2" 更改为 "typescript": "~3.2.4"

第 3 步: 运行 npm update 在您的项目中。

Step4:现在运行ng serve

Here is Stackblitz demo

希望这会有所帮助!