无法在 app.module 中导入 MatDialogModule [英] cannot import MatDialogModule in app.module

查看:21
本文介绍了无法在 app.module 中导入 MatDialogModule的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am a beginner in angular, I am using angular material dialog box. first I added material to my project and use it from @angular/material.

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

When I add ( import { MatDialogModule } from '@angular/material/dialog'; )) in app.module.ts, get below error on compiling project

 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:

this is my 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"
      }
    }

推荐答案

我相信这个问题应该在你重新安装 ng (Angular) 后解决

I believe this issue should be resolved when you re-install ng (Angular)

参考重新安装:

打开终端

sudo npm uninstall -g angular-cli
sudo npm cache clean

(记住 sudo 意味着对整个机器进行全局更改 - 推荐用于此过程)

(remember sudo means doing a global change for your entire machine - recommended for this process)

为确保您的命令已成功运行,请使用以下方法进行验证:

To ensure your command has run successfully, validate using:

ng -v

如果仍然没有安装,请按照以下步骤操作:

If it still doesn't get installed follow below step:

它将显示 ng 路径.转到路径,如果它与任何文件链接,则删除相同的链接和实际的 ng 文件.在我的例子中,链接在 /usr/bin/ng 中,ng 文件的实际路径是 /lib/node_modules/@angular/cli/bin/ng.>

It will show the ng path. Go to the path and if it is linked with any file remove the same the link and actual ng file. In my case the link is in /usr/bin/ng and actual path of ng file is /lib/node_modules/@angular/cli/bin/ng.

sudo rm -rf /lib/node_modules/@angular/cli/bin/ng
sudo rm -rf /usr/bin/ng

这应该删除所需的 npm 和 ng (Angular).

This should remove the desired npm and ng (Angular).

要重新安装 ng,请运行:

To reinstall ng, run:

sudo npm install -g @angular/cli

让我知道这是否有效,否则您必须重新安装 npm,然后按照上述步骤操作.希望第一次尝试成功;)

Let me know if this works, else you got to reinstall npm and then follow above steps. Hope the first try works ;)

这篇关于无法在 app.module 中导入 MatDialogModule的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆