angular material design 弹窗使用

原理就是用MatDialog写一个弹窗组件,

在要使用弹窗的组件的地方调用那个组件。

在ui文档里 弹窗组件和调用组件是写在一个component.ts里面的

能使用,但是<mat-dialog-content></mat-dialog-content>会报找不到这个组件。

所以重新写一个组件。

在调用的组件

0.引入

import { MatDialog } from "@angular/material/dialog";
import { ApplyDialogComponent } from "./components/apply-dialog/apply-dialog.component";

1.构造函数中实列化

  constructor(
    public dialog: MatDialog
  ) {}

2.调用这个对话框

  openDialog() {
    const dialogRef = this.dialog.open(ApplyLacaraDialogComponent);
  }

3.在弹窗关闭时传入一些参数

//弹窗html
<mat-dialog-actions align="center">
  <button mat-stroked-button mat-dialog-close>取消</button>
  <button
    mat-flat-button
    color="primary"
    [mat-dialog-close]="true"
    cdkFocusInitial
  >
    申请
  </button>
</mat-dialog-actions>

4.可以在component.ts中接收参数

  openDialog() {
    const dialogRef = this.dialog.open(ApplyLacaraDialogComponent);
    dialogRef.afterClosed().subscribe((result) => {
      if (result) {
        //你的逻辑
      }
    });
  }

相关推荐

  1. 墨刀以及墨刀事件的使用

    2023-12-28 07:26:04       54 阅读
  2. 小程序

    2023-12-28 07:26:04       63 阅读
  3. 鸿蒙:警告

    2023-12-28 07:26:04       60 阅读
  4. CSS<span style='color:red;'>弹</span><span style='color:red;'>窗</span>

    CSS

    2023-12-28 07:26:04      26 阅读
  5. flutter 底部和中间

    2023-12-28 07:26:04       60 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-28 07:26:04       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-28 07:26:04       101 阅读
  3. 在Django里面运行非项目文件

    2023-12-28 07:26:04       82 阅读
  4. Python语言-面向对象

    2023-12-28 07:26:04       91 阅读

热门阅读

  1. Python地理数据机器学习数学

    2023-12-28 07:26:04       64 阅读
  2. git 项目带分支迁移到另一个 git 仓库

    2023-12-28 07:26:04       55 阅读
  3. 对话面试官---关于死锁----通俗易懂版

    2023-12-28 07:26:04       59 阅读
  4. 八股文打卡day11——计算机网络(11)

    2023-12-28 07:26:04       52 阅读
  5. UDP Ping程序实现--第4关:客户端创建UDP套接字

    2023-12-28 07:26:04       53 阅读
  6. Mybatis-Plus基础之Mapper增删改

    2023-12-28 07:26:04       55 阅读
  7. vol----学习随记!!!

    2023-12-28 07:26:04       55 阅读
  8. flask文件夹列表前文修订版

    2023-12-28 07:26:04       53 阅读