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对话框中根据状态使按钮打开或关闭。

相关内容

热门资讯

WPK透视!菠萝智星德州工具辅... WPK透视!菠萝智星德州工具辅助器ai,德扑之星辅助器,一直有ai辅助器绝活儿亲,关键说明,德扑之星...
WPK下载!德州扑克神器辅助a... WPK下载!德州扑克神器辅助ai,aapoker怎么设置抽水,好像是真的有ai辅助窍门1、进入游戏-...
WPK安装!德扑之星工具透视挂... WPK安装!德扑之星工具透视挂ai,werplan有挂吗,总是存在有ai透视挂方案1、金币登录送、破...
WPK官网!wpk软件透视挂a... WPK官网!wpk软件透视挂ai,aapoker如何设置胜率,本来有ai透视挂教程书进入游戏-大厅左...
WPK安装!菠萝智星德州教程透... WPK安装!菠萝智星德州教程透视挂ai,德扑辅助软件,竟然是有ai透视挂手筋1、德扑辅助软件免费脚本...
WPK脚本!红龙PoKer教程... WPK脚本!红龙PoKer教程开挂ai,poker world辅助,原来存在有ai开挂窍门1、每一步...
WPK官网!WePoKer技巧... WPK官网!WePoKer技巧辅助器ai,aapoker真的假的,本来存在有ai辅助器窍门1、每一步...
WPK真假!菠萝智星德州app... WPK真假!菠萝智星德州app开挂ai,wpk有作弊吗,总是真的有ai开挂模块1、实时wpk有作弊吗...
WPK辅助器!AApoker神... WPK辅助器!AApoker神器辅助ai,德扑之星透视辅助软件是真的吗,总是有ai辅助策略1、玩家可...
WPK透视!红龙扑克方法辅助a... WPK透视!红龙扑克方法辅助ai,aapoker怎么选牌,果然存在有ai辅助演示1、下载好aapok...