本文介绍了将Angular更新到版本9后,MatDialog停止工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有角度的项目,我在 https://update之后从7.2升级到了9. angular.io/#7.2:9.0

I had an angular project which I upgraded from 7.2 to 9 following the https://update.angular.io/#7.2:9.0

升级后,除了MatDialog之外的所有东西都在工作.打开对话框会显示一个不成比例的空白弹出窗口,控制台中显示以下错误.

Post upgrade everything except MatDialog is working. Opening the dialog shows an empty popup of disproportionate size with the following error in the console.

core.js:3866 ERROR Error: Uncaught (in promise): TypeError: Cannot read property "hasAttached" of undefined
TypeError: Cannot read property "hasAttached" of undefined
    at MatDialogContainer.push../node_modules/@angular/material/esm5/dialog.es5.js.MatDialogContainer.attachComponentPortal (dialog.es5.js:191)
    at MatDialog.push../node_modules/@angular/material/esm5/dialog.es5.js.MatDialog._attachDialogContent (dialog.es5.js:1046)
    at MatDialog.push../node_modules/@angular/material/esm5/dialog.es5.js.MatDialog.open (dialog.es5.js:850)
    at new AppComponent (app.component.ts:67)
    at createClass (core.js:22218)
    at createDirectiveInstance (core.js:22087)
    at createViewNodes (core.js:30632)
    at createRootView (core.js:30546)
    at callWithDebugContext (core.js:31554)
    at Object.debugCreateRootView [as createRootView] (core.js:31064)
    at resolvePromise (zone.js:836)
    at resolvePromise (zone.js:795)
    at zone.js:897
    at ZoneDelegate.invokeTask (zone.js:431)
    at Object.onInvokeTask (core.js:27441)
    at ZoneDelegate.invokeTask (zone.js:430)
    at Zone.runTask (zone.js:198)
    at drainMicroTaskQueue (zone.js:611)
    at ZoneTask.invokeTask [as invoke] (zone.js:517)
    at invokeTask (zone.js:1671)

我已经从本教程中进行了验证 https://www.techiediaries.com/angular- material-dialogs/中,使用带有自定义组件的对话框的方式是相同的.由于工作政策,我无法提供实际的代码.

I have verified from this tutorial https://www.techiediaries.com/angular-material-dialogs/ that the way to use dialog with a custom component is the same.I am not able to provide the actual code because of work policy.

根据此链接.但这没有帮助.

你们中有人也遇到过类似的问题吗?

Did anyone of you also face a similar issue?

推荐答案

问题已解决.我必须将Angular Material CDK升级到9.1,并将所有导入引用更改为新格式:

Problem solved. I had to upgrade Angular Material CDK to 9.1 and change all import references to the new format:

import { MatDialogModule } from '@angular/material/dialog';

一切都好!

这篇关于将Angular更新到版本9后,MatDialog停止工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

查看更多