Angularslide-toggle不响应确认弹窗后的操作
创始人
2024-10-29 16:00:56
0

在 slide-toggle 组件中添加一个 confirm 弹窗,当用户改变开关状态时弹出,等待用户确认后再更新数据。可以通过以下代码实现:

HTML:


  Slide Toggle

TypeScript:

import { MatDialog } from '@angular/material/dialog';
import { ConfirmDialogComponent } from './confirm-dialog/confirm-dialog.component';

export class MyComponent {
  isChecked = false;

  constructor(public dialog: MatDialog) {}

  confirmToggle(event: MatSlideToggleChange): void {
    const dialogRef = this.dialog.open(ConfirmDialogComponent, {
      data: { isChecked: event.checked }
    });

    dialogRef.afterClosed().subscribe(result => {
      if (result === 'confirm') {
        // 用户点击确认,更新数据
        this.isChecked = event.checked;
      } else {
        // 用户取消操作,还原开关状态
        this.isChecked = !event.checked;
      }
    });
  }
}

在 confirm-dialog.component.ts 中实现 ConfirmDialogComponent 组件,该组件可以通过 MatDialog 打开对话框,允许用户确认或取消操作。

HTML:

Confirm

Are you sure you want to toggle the switch?

TypeScript:

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

@Component({
  selector: 'app-confirm-dialog',
  templateUrl: './confirm-dialog.component.html'
})
export class ConfirmDialogComponent {
  constructor(
    public dialogRef: MatDialogRef,
    @Inject(MAT_DIALOG_DATA) public data: { isChecked: boolean }
  ) {}

  onCancelClick(): void {
    this.dialogRef.close();
  }
}

相关内容

热门资讯

透视攻略!德普之星透视辅助软件... 透视攻略!德普之星透视辅助软件下载,sohoo poker辅助,透牌教程(最初是有挂)1、许多玩家不...
透视脚本!aapoker透视脚... 透视脚本!aapoker透视脚本下载,红龙poker作弊指令,最新研发(有挂攻略)1、起透看视 aa...
透视了解!wepoker免费永... 透视了解!wepoker免费永久脚本,wepoker模拟器哪个好用,可靠教程(起初是真的有挂);we...
透视玄学!wepoker透视版... 透视玄学!wepoker透视版下载,hhpoker怎么开透视,大神普及(有挂透明)是一款可以让一直输...
透视好牌!红龙poker作弊指... 透视好牌!红龙poker作弊指令,wejoker辅助器怎么卖,实用技巧(原先真的是有挂);亲真的是有...
透视讲解!aapoker辅助是... 透视讲解!aapoker辅助是真的吗,德普之星透视辅助软件下载,总算清楚(有挂黑科技);小薇(透视辅...
透视透视!aapoker透视脚... 透视透视!aapoker透视脚本安装包,wepoker开辅助能查到吗,2025版教程(其实有挂);玩...
透视好友!aapoker透视脚... 透视好友!aapoker透视脚本下载,智星德州菠萝透视插件工具,交流学习经验(有挂辅助挂)您好,智星...
透视ai代打!wpk透视脚本,... 透视ai代打!wpk透视脚本,wpk透视插件,实用技巧(原先真的是有挂);wpk透视脚本软件透明挂作...
透视好友!wepoker底牌透... 透视好友!wepoker底牌透视脚本,wpk透视脚本视频,玩家攻略推荐(有挂规律);致您一封信;亲爱...