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

相关内容

热门资讯

三分钟了解!we poker免... 三分钟了解!we poker免费辅助器(辅助挂)切实是真的有挂(有挂教学)运we poker免费辅助...
玩家必看教程!hhpoker必... 玩家必看教程!hhpoker必备开挂(辅助挂)竟然有挂(有挂方法)1、下载好hhpoker必备开挂透...
一分钟揭秘!we-poker有... 一分钟揭秘!we-poker有人玩吗(辅助挂)竟然真的是有挂(证实有挂)该软件可以轻松地帮助玩家将w...
发现玩家!poker worl... 发现玩家!poker world辅助(辅助挂)本来真的是有挂(有挂神器)1、实时poker worl...
揭秘关于!哈糖大菠萝开挂(辅助... 揭秘关于!哈糖大菠萝开挂(辅助挂)总是是真的有挂(有挂方法)1、首先打开哈糖大菠萝开挂辅助器下载最新...
必看攻略!德普之星透视辅助软件... 必看攻略!德普之星透视辅助软件下载(辅助挂)都是存在有挂(真的有挂)运德普之星透视辅助软件下载辅助工...
玩家必知教程!wepoker怎... 玩家必知教程!wepoker怎么看牌型(辅助挂)其实有挂(有挂教程)1、金币登录送、破产送、升级送、...
我来分享!约局吧能不能开挂(辅... 我来分享!约局吧能不能开挂(辅助挂)总是真的是有挂(有挂透视)亲,关键说明,约局吧能不能开挂透视脚本...
技术分享!wepoker免费脚... 技术分享!wepoker免费脚本咨询(辅助挂)竟然真的是有挂(有挂攻略)一、wepoker免费脚本咨...
重大通报!wepoker免费钻... 重大通报!wepoker免费钻石(辅助挂)切实有挂(真的有挂)1、全新机制【wepoker免费钻石a...