gpt4 book ai didi

angular - 无法在 app.module 中导入 MatDialogModule

转载 作者:行者123 更新时间:2023-12-03 15:06:43 25 4
gpt4 key购买 nike

我是 Angular 初学者,
我正在使用 Angular Material 对话框。首先,我在我的项目中添加了 Material 并从 @angular/material 使用它.

当我在 import { MatDialogModule } from '@angular/material/dialog'; 中添加 ( app.module.ts )) 时, 在编译项目时出现以下错误

 ERROR in node_modules/@angular/cdk/coercion/array.d.ts(10,60): error
TS1005: ',' expected.
node_modules/@angular/cdk/coercion/array.d.ts(10,61): error TS1005:
',' expected. node_modules/@angular/cdk/coercion/array.d.ts(10,75):
error TS1144: '{' or ';' expected.
node_modules/@angular/cdk/coercion/array.d.ts(10,77): error TS1011: An
element access expression should take an argument.

为什么?

这是我的 package.json:
      {
"name": "sales-maret",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^7.2.16",
"@angular/cdk": "^9.2.0",
"@angular/common": "~7.2.0",
"@angular/compiler": "~7.2.0",
"@angular/core": "~7.2.0",
"@angular/forms": "~7.2.0",
"@angular/material": "^9.2.0",
"@angular/platform-browser": "~7.2.0",
"@angular/platform-browser-dynamic": "~7.2.0",
"@angular/router": "~7.2.0",
"core-js": "^2.5.4",
"hammerjs": "^2.0.8",
"material-icons": "^0.3.1",
"rxjs": "~6.3.3",
"tslib": "^1.9.0",
"zone.js": "~0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.13.0",
"@angular/cli": "~7.3.6",
"@angular/compiler-cli": "~7.2.0",
"@angular/language-service": "~7.2.0",
"@types/node": "~8.9.4",
"@types/jasmine": "~2.8.8",
"@types/jasminewd2": "~2.0.3",
"codelyzer": "~4.5.0",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~4.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.11.0",
"typescript": "~3.2.2"
}
}

最佳答案

错误是因为@angular/material、@angular/cdk 和@angular/core 包的版本号不匹配。包 @angular/material 和 @angular/cdk 的版本是 9.2.0 但 @angular/core 的版本是 7.2.0 。

为了正常运行,三个包应该具有相同的版本。

您应该卸载@angular/material 和@angular/cdk 包,然后安装旧版本。

npm uninstall @angular/material
npm uninstall @angular/cdk
npm install @angular/material@7.2.0
npm install @angular/cdk@7.2.0

关于angular - 无法在 app.module 中导入 MatDialogModule,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60949170/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com