Angular对话框:如何根据状态使按钮打开或关闭
创始人
2024-10-24 15:31:38
0

为了根据状态在Angular对话框中使按钮打开或关闭,我们需要使用DialogRef并在template中添加ngIf指令。以下是步骤:

1.在dialog component中,注入DialogRef。

import { Component, OnInit, Inject } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from "@angular/material/dialog";

@Component({
  selector: 'app-dialog-example',
  templateUrl: './dialog-example.component.html',
  styleUrls: ['./dialog-example.component.css']
})
export class DialogExampleComponent implements OnInit {
  //injecting DialogRef
  constructor(public dialogRef: MatDialogRef) { }

  ngOnInit() {
  }

}

2.在template中,使用DialogRef访问传递给Dialog的数据,并设置标志以在根据状态打开或关闭按钮。在这里,我使用data中的isOpen标志。

Dialog Example

Dialog Content

是的,这是我们需要的。现在,让我们来看看如何在打开Dialog之前设置isOpen标志。

3.在打开Dialog时,添加一个字典,并将isOpen标志设置为true。在这里,我使用openDialog()方法。

import { Component } from '@angular/core';
import { MatDialog } from "@angular/material/dialog";
import { DialogExampleComponent } from "./dialog-example/dialog-example.component";

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  isOpen:boolean = false;
  constructor(public dialog: MatDialog){}

  openDialog(){
    let dialogRef = this.dialog.open(DialogExampleComponent,{
      data : {isOpen : true}
    });
  }
}

现在当我们调用openDialog()方法时,我们会得到一个具有isOpen标志的Dialog。

希望这能帮助您在Angular对话框中根据状态使按钮打开或关闭。

相关内容

热门资讯

一分钟了解!wepoker分析... 一分钟了解!wepoker分析,wepoker透视脚本网页,其实真的有挂(有挂秘籍)1、游戏颠覆性的...
交流学习经验!aapoker如... 交流学习经验!aapoker如何设置胜率,德扑之心免费透视,真是存在有挂(有挂秘诀)1、上手简单,内...
免费测试版!拱趴大菠萝自动计算... 免费测试版!拱趴大菠萝自动计算机器人,wepoker私局代打,好像真的是有挂(有挂总结)1、每一步都...
我来教大家!wepoker有辅... 我来教大家!wepoker有辅助工具吗,德州透视竞技联盟,都是真的是有挂(了解有挂)1、每一步都需要...
一分钟了解!wepoker私人... 一分钟了解!wepoker私人局透视方法,werplan怎么作弊,好像真的是有挂(有挂教学)1)辅助...
玩家科普!wepoker透视器... 玩家科普!wepoker透视器免费,安装不了wepoker,果然存在有挂(有挂方略)小薇(辅助器软件...
科技揭秘!佛手大菠萝有挂吗,w... 科技揭秘!佛手大菠萝有挂吗,wepoker破解工具,果然有挂(有挂细节)1)辅助插件:进一步探索辅助...
教程辅助!wepoker怎么提... 教程辅助!wepoker怎么提高运气,拱趴大菠萝有什么挂,都是真的是有挂(有挂技巧)脚本下载中分为三...
一分钟揭秘!we-poker正... 一分钟揭秘!we-poker正规吗,wepoker轻量版透视,一贯真的是有挂(有挂攻略)1、游戏颠覆...
重大发现!wepoker透视版... 重大发现!wepoker透视版下载,werplan脚本,真是真的有挂(有挂存在)1、打开软件启动之后...