Angular 10中未提供ModalDialogService的错误。
创始人
2024-10-15 09:00:41
0

在 Angular 10 中,ModalDialogService 不再可用,因为它已被废弃。取而代之的是使用 Angular Material 中的 MatDialog 组件来创建模态对话框。

以下是一个解决方法的代码示例:

  1. 首先,确保已经安装了 @angular/material 包。如果没有安装,可以使用以下命令进行安装:
npm install @angular/material
  1. 在需要使用模态对话框的组件中,导入 MatDialog
import { MatDialog } from '@angular/material/dialog';
  1. 在组件的构造函数中注入 MatDialog
constructor(private dialog: MatDialog) { }
  1. 创建一个方法来打开模态对话框:
openDialog() {
  const dialogRef = this.dialog.open(YourDialogComponent, {
    width: '250px',
    data: { name: 'John', age: 30 } // 传递给模态对话框的数据
  });

  dialogRef.afterClosed().subscribe(result => {
    console.log('The dialog was closed');
    console.log(result); // 模态对话框关闭时返回的结果
  });
}
  1. 创建一个新的组件来作为模态对话框的内容。
import { Component, Inject } from '@angular/core';
import { MAT_DIALOG_DATA } from '@angular/material/dialog';

@Component({
  selector: 'app-your-dialog',
  template: `
    

Modal Dialog

Name: {{ data.name }}

Age: {{ data.age }}

`, }) export class YourDialogComponent { constructor(@Inject(MAT_DIALOG_DATA) public data: any) { } closeDialog() { // 关闭模态对话框 this.dialogRef.close(); } }

在上述代码中,YourDialogComponent 是用来显示模态对话框的组件。你可以根据自己的需求进行自定义。

最后,在你的模板文件中添加一个按钮或其他触发器来调用 openDialog() 方法:


当点击按钮时,将会打开一个基于 YourDialogComponent 组件的模态对话框。

相关内容

热门资讯

透视模拟器!wepoker是不... 透视模拟器!wepoker是不是有人用挂(透视)竟然真的是有挂(详细辅助普及教程)1、玩家可以在软件...
科技分享!hhpoker作弊实... 1、科技分享!hhpoker作弊实战视频,wepoker怎么拿到好牌,解说技巧(有挂方法);详细教程...
透视ai!wepoker免费钻... 透视ai!wepoker免费钻石(透视)都是真的有挂(详细辅助系统教程);小薇(透视辅助)致您一封信...
一分钟教你!hhpoker是正... 一分钟教你!hhpoker是正品吗,wepoker有透视底牌吗,必赢方法(有挂透视)1、很好的工具软...
透视辅助!xpoker辅助怎么... 透视辅助!xpoker辅助怎么用(透视)好像是真的有挂(详细辅助教你教程)1、ai机器人多个强度级别...
解密关于!hhpoker作弊码... 这是一款非常优秀的wepokerplus万能挂 ia辅助检测软件,能够让你了解到wepokerplu...
2分钟细说!hhpoker怎么... 2分钟细说!hhpoker怎么防作弊,wejoker辅助软件视频,软件教程(有挂方法);玩家必备必赢...
透视游戏!wepoker钻石怎... 透视游戏!wepoker钻石怎么看底牌(透视)其实是真的有挂(详细辅助线上教程)1、机器人多个强度级...
透视工具!wepoker亲友圈... 透视工具!wepoker亲友圈有用吗(透视)原来是有挂(详细辅助德州论坛)1、金币登录送、破产送、升...
推荐一款!wepoker辅助器... 推荐一款!wepoker辅助器怎么弄,aapoker如何设置胜率,德州论坛(有挂软件)是一款可以让一...