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透视脚本免费下载(透视)果然是真的有挂(详细辅助必胜教程);1、wepoke...
透视攻略!hhpoker的辅助... 透视攻略!hhpoker的辅助是真的吗(透视)其实是有挂(详细辅助新版2025教程)1、完成透视辅助...
透视攻略!wepoker透视脚... 透视攻略!wepoker透视脚本免费下载pc(透视)竟然存在有挂(详细辅助教你攻略);1)wepok...
透视插件!聚星ai辅助工具下载... 透视插件!聚星ai辅助工具下载(透视)原来真的有挂(详细辅助揭秘教程);辅助器中分为三种模型:软件透...
透视新版!hhpoker真能买... 透视新版!hhpoker真能买到挂吗(透视)竟然有挂(详细辅助详细教程);1、这是跨平台的黑科技,在...
透视了解!竞技联盟透视插件(透... 透视了解!竞技联盟透视插件(透视)一贯真的是有挂(详细辅助2025新版);1、全新机制【软件透明挂】...
透视玄学!wepoker可以开... 透视玄学!wepoker可以开透视吗(透视)其实是真的有挂(详细辅助规律教程)软件透明挂微扑克wpk...
透视软件!淘宝买wepoker... 透视软件!淘宝买wepoker透视有用吗(透视)本来真的是有挂(详细辅助专业教程);暗藏猫腻,小编详...
透视玄学!hh poker软件... 透视玄学!hh poker软件(透视)真是真的是有挂(详细辅助实用技巧);1、系统规律教程、辅助透视...
透视科技!大菠萝789辅助器下... 透视科技!大菠萝789辅助器下载(透视)一贯存在有挂(详细辅助安装教程)1、玩家可以在软件透明挂俱乐...