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

相关内容

热门资讯

透视科技"wepok... 透视科技"wepoker透视脚本免费app"hh poker透视器下载(其实真的有辅助神器)-哔哩哔...
随着"拱趴大菠萝机器... 随着"拱趴大菠萝机器人"pokemmo脚本辅助器下载(总是是有辅助工具)-哔哩哔哩1、任何pokem...
透视美元局"约局吧游... 透视美元局"约局吧游戏挂"pokermaster修改器(好像真的是有辅助下载)-哔哩哔哩进入游戏-大...
透视总结"德普辅助器... 透视总结"德普辅助器怎么用"智星德州有脚本吗(好像存在有辅助修改器)-哔哩哔哩1、完成德普辅助器怎么...
透视美元局"德州透视... 透视美元局"德州透视竞技联盟"德普之星透视(都是存在有辅助平台)-哔哩哔哩1、这是跨平台的德州透视竞...
透视规律"hhpok... 透视规律"hhpoker辅助软件是真的么"wepoker的辅助器(原来真的是有辅助平台)-哔哩哔哩;...
透视神器"fishp... 透视神器"fishpoker透视底牌"wepoker有没有机器人(一直真的是有辅助app)-哔哩哔哩...
连日来"智星德州插件... 连日来"智星德州插件2024最新版"wepoker有没有机器人(一直真的是有辅助工具)-哔哩哔哩1、...
透视黑科技"fish... 透视黑科技"fishpoker透视底牌"wepoker底牌透视(果然真的有辅助工具)-哔哩哔哩1、f...
无独有偶"wepok... 无独有偶"wepoker辅助器安装包定制"aapoker透视脚本(真是是真的辅助平台)-哔哩哔哩we...