TypeError: Object(...) 不是角度材质的函数 [英] TypeError: Object(...) is not a function for angular-material

查看:32
本文介绍了TypeError: Object(...) 不是角度材质的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 angular 7 中,尝试使用有角度的材料 mat-dialog-content.在 app.module.ts 中导入时出现以下错误:

In angular 7, trying to use angular material mat-dialog-content. While importing in app.module.ts it gives the following error:

TypeError: Object(...) 不是这样的函数: Uncaught TypeError:Object(...) 不是函数在platform.es5.js:102.

TypeError: Object(...) is not a function like: Uncaught TypeError: Object(...) is not a function at platform.es5.js:102.

package.json

{
  "name": "image-cropp",
  "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.15",
    "@angular/cdk": "^8.0.1",
    "@angular/common": "~7.2.0",
    "@angular/compiler": "~7.2.0",
    "@angular/core": "~7.2.0",
    "@angular/forms": "~7.2.0",
    "@angular/material": "^8.0.1",
    "@angular/platform-browser": "~7.2.0",
    "@angular/platform-browser-dynamic": "~7.2.0",
    "@angular/router": "~7.2.0",
    "core-js": "^2.5.4",
    "ngx-image-cropper": "^1.4.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.5",
    "@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"
  }
}

module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { ImageCropComponent } from './image-crop/image-crop.component';
import { MatDialogModule } from '@angular/material';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';


@NgModule({
  declarations: [
    AppComponent,
    ImageCropComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    MatDialogModule,
    BrowserAnimationsModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

是否有任何依赖问题或其他问题?

Is there any dependency problem or something else?

推荐答案

    "@angular/animations": "^7.2.15",
    "@angular/cdk": "^8.0.1",
    "@angular/common": "~7.2.0",
    "@angular/compiler": "~7.2.0",
    "@angular/core": "~7.2.0",
    "@angular/forms": "~7.2.0",
    "@angular/material": "^8.0.1",
    "@angular/platform-browser": "~7.2.0",
    "@angular/platform-browser-dynamic": "~7.2.0",

您在版本 8 中使用 @angular/cdk@angular/material 以及 @angular/core @angular/common 7.如果您想停留在 Angular 7,请卸载 cdk 和材料并安装版本 7 的特定 cdk 和材料.

You use @angular/cdk and @angular/material in version 8 together with @angular/core @angular/common 7. If you want to stay at Angular 7 uninstall cdk and material and install the specific cdk and material for version 7.

npm uninstall @angular/cdk @angular/material

... find out the version 7

npm show @angular/cdk versions
npm show @angular/material versions

... and then install the specific one

npm install @angular/cdk@7.2.15

或者只是升级你的角度

npm install -g @angular/cli@latest
ng update @angular/cli @angular-devkit/build-angular
ng update @angular/core @angular/cdk @angular/material

在这两个选项之一之后再试一次.

After one of this two options try it again.

这篇关于TypeError: Object(...) 不是角度材质的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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